Loading...
Flex

De Flex à PHP via JSON

Pour envoyer des données de FLEX à un serveur PHP on peut utiliser XML ou JSON.
JSON (JavaScript Object Notation) est un format de données générique. Il utilise la notation des objets JavaScript pour transmettre de l’information structurée.

Pour utiliser Json dans Flex il faut tout d’abord récupérer le .swc à mettre dans le dossier lib de votre projet Flex. Ici le lien Adobe Flex coreLib.

Côté PHP si vous avez une version supérieure à 5.2 pas de soucis si non il faudra récupérer le code ici : php-json

Donc dans l’application Flex on aura :

import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import com.adobe.serialization.json.JSON;

Une fonction pour envoyer les data. list de votre dataProvider est encodé via Json en string. Les data sont envoyé via le service sendData.

private function sendPHPData():void
{
var objSend:Object = new Object();
var dataString:String = JSON.encode(list.dataProvider.toArray());
dataString = escape(dataString);
objSend.setTutorials = « true »;
objSend.jsonSendData = dataString;
sendData.send(objSend);
}

et bien sûr :

<mx:HTTPService id=« sendData » url=« sendData.php »

useProxy=« false » method=« GET » resultFormat=« text »

result=« updatedPHPDataResult(event) »>

</mx:HTTPService>

<mx:ArrayCollection id= »myData »></mx:ArrayCollection>

<mx:List id= »list » dataProvider= »{myData} »/>

C’est le code que l’on trouve sur tous les tutoriels. Malheureusement il ne fonctionne pas toujours. J’ai essayé pendant plusieurs jours sur IE7 explorer 7 de transférer des data et curieusement au bout d’un certain nombre de données aucun appel au script PHP. Il y a donc un problème de mémoire cache. Je conseille donc de ne pas utiliser GET mais POST.

Le code PHP :

<?php

if (isset($_REQUEST[‘jsonSendData’])) $jsonString = $_REQUEST[‘jsonSendData’];

$jsonString = urldecode($jsonString);

$data = json_decode($jsonString, true);
print_r($data);

?>

83 comments
  1. bape

    I simply wanted to thank you so much yet again. I do not know the things I would have accomplished in the absence of the actual information discussed by you on such area. It was actually a horrifying matter in my position, but witnessing this specialised mode you processed it forced me to weep over happiness. Now i am happier for the guidance and then hope you recognize what a great job you have been putting in educating people today with the aid of your blog. More than likely you have never met any of us.

  2. giannis antetokounmpo shoes

    Needed to write you this little remark to be able to say thank you again for all the incredible concepts you have contributed in this article. It’s pretty generous of people like you to give openly what exactly many of us would have offered for sale for an e book to generate some bucks for their own end, mostly seeing that you could have done it if you ever decided. Those basics also served as a great way to be aware that other individuals have the identical desire just as mine to see a great deal more pertaining to this issue. I’m certain there are numerous more pleasurable sessions ahead for those who look over your site.

  3. off white clothing

    I have to get across my love for your kind-heartedness giving support to those who need assistance with this important content. Your very own dedication to passing the message around came to be remarkably informative and have constantly made guys like me to achieve their endeavors. Your amazing invaluable facts denotes a whole lot to me and much more to my mates. Thank you; from everyone of us.

  4. supreme

    I have to express my appreciation for your generosity in support of men who really need help with the theme. Your personal commitment to passing the solution around was astonishingly insightful and have always allowed employees much like me to achieve their objectives. Your amazing informative guideline means so much to me and far more to my office colleagues. Best wishes; from each one of us.

  5. supreme

    I would like to voice my affection for your generosity in support of persons that absolutely need assistance with the field. Your very own dedication to passing the solution along appeared to be particularly interesting and have all the time allowed folks much like me to reach their ambitions. Your amazing important publication denotes a lot a person like me and a whole lot more to my colleagues. Thank you; from all of us.

  6. kd 15

    I precisely wished to thank you so much again. I do not know what I could possibly have worked on in the absence of the entire aspects contributed by you on such industry. It was an absolute frightening scenario for me, but looking at your expert fashion you processed it made me to jump over delight. Now i’m thankful for this help and as well , pray you are aware of a powerful job your are undertaking educating some other people through the use of your website. More than likely you have never encountered all of us.

  7. air jordan travis scott

    I’m also commenting to let you know of the incredible encounter my friend’s daughter undergone visiting your blog. She learned a good number of pieces, including what it is like to have an ideal coaching mood to make many more without hassle understand a number of extremely tough matters. You really exceeded our own desires. I appreciate you for rendering these warm and helpful, dependable, informative and as well as fun tips on this topic to Lizeth.

  8. supreme clothing

    I wish to convey my respect for your generosity in support of individuals who must have help with in this question. Your very own dedication to getting the solution all over appears to be extraordinarily helpful and has usually allowed workers like me to realize their aims. Your valuable help indicates much to me and especially to my fellow workers. Regards; from each one of us.

  9. curry 8

    I would like to point out my respect for your kind-heartedness giving support to those who need assistance with your subject matter. Your very own commitment to passing the message up and down had become extraordinarily insightful and have continually helped women like me to get to their ambitions. Your new warm and helpful instruction implies a whole lot to me and a whole lot more to my fellow workers. Thank you; from everyone of us.

  10. goyard

    I have to voice my passion for your generosity giving support to folks that must have guidance on the concept. Your personal dedication to getting the message all through was incredibly important and have in most cases empowered some individuals much like me to realize their aims. Your amazing valuable help entails much a person like me and still more to my peers. Warm regards; from all of us.

  11. fear of god essentials

    I simply wanted to say thanks yet again. I do not know what I would’ve undertaken without the actual concepts shared by you regarding this area. Previously it was the distressing case in my opinion, nevertheless understanding a expert manner you processed the issue took me to cry over delight. I’m happy for this information and thus pray you realize what an amazing job you are doing training the rest with the aid of your site. Most likely you have never encountered all of us.

  12. curry shoes

    I precisely had to say thanks once again. I’m not certain the things I would’ve accomplished in the absence of these tactics shared by you relating to such area of interest. It was actually an absolute fearsome issue in my position, but discovering a skilled manner you handled the issue forced me to weep over delight. Now i’m happier for this assistance and thus pray you realize what a powerful job you are always providing teaching most people through the use of your blog. I know that you haven’t met all of us.

  13. supreme clothing

    I precisely wanted to thank you so much all over again. I’m not certain the things that I could possibly have made to happen in the absence of the entire suggestions shared by you concerning such a field. Entirely was a very troublesome case in my circumstances, however , observing your specialised avenue you treated it forced me to cry over fulfillment. I’m just happy for your work and then have high hopes you find out what a great job that you are undertaking training the others by way of a web site. Most probably you have never come across any of us.

  14. westbrook shoes

    Thanks a lot for providing individuals with a very terrific possiblity to read critical reviews from here. It really is so lovely and full of fun for me personally and my office friends to search the blog at the least 3 times every week to read through the latest tips you will have. And indeed, I’m so at all times impressed concerning the outstanding tips you give. Some 3 tips in this post are absolutely the most suitable we have had.

  15. off white shoes

    I precisely desired to appreciate you again. I am not sure what I could possibly have implemented without these techniques provided by you relating to this industry. It seemed to be an absolute challenging difficulty for me personally, but being able to see the very skilled mode you dealt with that forced me to jump over delight. Now i’m grateful for your support and even wish you really know what a great job you are always providing instructing the rest using your webpage. I am sure you have never met any of us.

  16. bapesta

    I want to convey my love for your kind-heartedness giving support to those who actually need assistance with that matter. Your special commitment to getting the message along ended up being extremely helpful and have regularly enabled those much like me to achieve their goals. Your entire informative help implies much to me and even more to my colleagues. Regards; from all of us.

  17. bape clothing

    I would like to show my gratitude for your kind-heartedness in support of men who require guidance on this theme. Your personal commitment to passing the message up and down has been rather significant and have consistently enabled women like me to get to their endeavors. Your warm and friendly tutorial indicates much to me and even more to my mates. Thank you; from everyone of us.

  18. off white outlet

    I precisely wished to appreciate you yet again. I am not sure what I would have taken care of in the absence of the actual recommendations revealed by you regarding that area. Certainly was an absolute difficult crisis in my circumstances, but understanding the very skilled mode you dealt with that took me to weep for fulfillment. I am just happy for this work as well as trust you realize what a powerful job that you are providing instructing others thru a web site. I am certain you have never got to know any of us.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.