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;

et bien sûr :

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

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

result=« updatedPHPDataResult(event) »>


<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 :


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

$jsonString = urldecode($jsonString);

$data = json_decode($jsonString, true);


  1. a bathing ape

    I must point out my gratitude for your generosity in support of visitors who have the need for assistance with the area of interest. Your very own dedication to passing the message throughout turned out to be extraordinarily productive and has without exception encouraged folks just like me to realize their goals. The useful suggestions entails much a person like me and much more to my mates. Thank you; from everyone of us.

  2. giannis antetokounmpo shoes

    I want to show my admiration for your kind-heartedness giving support to persons that actually need guidance on your idea. Your special dedication to getting the message up and down came to be definitely interesting and have always made regular people like me to reach their ambitions. Your entire warm and helpful facts signifies this much a person like me and further more to my mates. With thanks; from everyone of us.

  3. supreme hoodie

    I want to point out my appreciation for your kindness for folks who need help with this niche. Your personal commitment to passing the solution all over had been extraordinarily informative and have really enabled ladies like me to get to their aims. The warm and helpful tutorial signifies so much to me and additionally to my colleagues. Regards; from all of us.

  4. kyrie 7 shoes

    I want to show appreciation to the writer for rescuing me from this particular circumstance. Because of browsing throughout the the net and coming across tips which are not productive, I thought my life was gone. Existing without the answers to the issues you’ve solved through your report is a critical case, and the ones that could have negatively damaged my career if I hadn’t discovered your website. Your good capability and kindness in dealing with every aspect was invaluable. I am not sure what I would’ve done if I hadn’t discovered such a step like this. I can at this point look forward to my future. Thank you so much for your reliable and result oriented help. I won’t hesitate to refer the website to anybody who needs counselling on this matter.

  5. kyrie 6

    I wish to show my appreciation to you just for rescuing me from this crisis. Just after scouting throughout the internet and getting notions that were not powerful, I was thinking my entire life was well over. Being alive devoid of the answers to the difficulties you’ve sorted out as a result of your report is a critical case, and the kind that might have adversely damaged my career if I had not discovered the website. Your actual natural talent and kindness in maneuvering every part was tremendous. I don’t know what I would’ve done if I hadn’t come across such a thing like this. I can at this moment look ahead to my future. Thanks for your time so much for your impressive and result oriented guide. I will not hesitate to refer the blog to any individual who needs and wants counselling on this area.

  6. kyrie spongebob

    I precisely needed to thank you so much once more. I’m not certain the things I would’ve gone through without these strategies provided by you relating to this situation. Completely was a terrifying problem in my circumstances, but seeing a specialized style you handled the issue forced me to leap for happiness. I’m thankful for the information and have high hopes you know what a great job you happen to be carrying out training people today using your blog. I am certain you have never come across all of us.

  7. curry 6

    I am just commenting to let you understand what a cool discovery my friend’s daughter encountered visiting your blog. She even learned lots of issues, which included what it’s like to have an incredible giving mood to get many people with no trouble know precisely a variety of advanced things. You truly exceeded her desires. Thank you for showing the valuable, trusted, revealing not to mention fun tips on your topic to Lizeth.

  8. curry 6

    I’m also writing to let you be aware of what a outstanding discovery my wife’s child found browsing your site. She came to find a good number of issues, not to mention what it’s like to have a great teaching mindset to have a number of people really easily know just exactly some very confusing subject matter. You undoubtedly exceeded our own expectations. Thanks for distributing those priceless, dependable, explanatory and fun tips on this topic to Julie.

  9. jordan 6

    I have to convey my admiration for your kind-heartedness for people that really want guidance on this important topic. Your very own commitment to getting the message all over became exceptionally interesting and have continually helped guys and women like me to get to their pursuits. This useful facts can mean this much a person like me and even more to my fellow workers. Thank you; from all of us.

  10. supreme clothing

    I actually wanted to write down a small comment to appreciate you for all of the unique suggestions you are writing here. My considerable internet investigation has at the end been paid with good quality facts to write about with my companions. I would claim that many of us visitors are unquestionably blessed to dwell in a really good place with many lovely professionals with valuable strategies. I feel very much lucky to have come across the webpage and look forward to many more awesome times reading here. Thanks a lot once again for everything.

  11. kyrie 5 spongebob

    I precisely wished to thank you so much again. I am not sure what I could possibly have followed in the absence of the type of creative ideas shared by you regarding that area of interest. Completely was a intimidating crisis in my position, but being able to view the very professional strategy you treated that made me to jump over happiness. I’m happier for this support and as well , hope that you comprehend what a great job that you’re undertaking teaching the others all through a site. Most probably you haven’t met any of us.

  12. kd shoes

    I have to express my admiration for your generosity giving support to visitors who must have help with this particular topic. Your very own dedication to passing the solution all through ended up being particularly beneficial and has empowered girls much like me to reach their aims. Your own helpful hints and tips entails a lot to me and extremely more to my mates. Thanks a lot; from each one of us.

  13. yeezy

    I actually wanted to post a quick word so as to express gratitude to you for all the stunning instructions you are giving here. My prolonged internet search has at the end been rewarded with high-quality suggestions to talk about with my great friends. I ‘d point out that many of us visitors actually are very much lucky to be in a really good website with so many special people with insightful secrets. I feel extremely fortunate to have come across your website and look forward to really more brilliant minutes reading here. Thanks a lot once again for all the details.

  14. Erma

    Please let me know if you’re looking for a writer for your site.

    You have some really good articles and I feel I
    would be a good asset. If you ever want to take
    some of the load off, I’d love to write some articles for
    your blog in exchange for a link back to mine.
    Please send me an e-mail if interested. Kudos!

  15. bape clothing

    I wish to convey my passion for your kind-heartedness for those people who actually need assistance with that niche. Your very own commitment to passing the message along had become certainly important and has continually permitted others just like me to arrive at their targets. Your entire useful help can mean much a person like me and additionally to my peers. Best wishes; from each one of us.

  16. curry 6

    I needed to compose you one very little observation to be able to give many thanks yet again over the great knowledge you have shown on this site. It is simply strangely open-handed of people like you to convey openly just what some people could have sold for an e book to help make some dough on their own, mostly now that you could possibly have done it in the event you considered necessary. These basics as well acted like a easy way to be certain that many people have the identical desire the same as my own to understand much more with regards to this condition. I believe there are millions of more pleasant instances ahead for individuals who view your website.

Laisser un commentaire

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