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. yeezy 700

    I have to show my gratitude for your generosity for men who actually need guidance on in this situation. Your real commitment to getting the solution across turned out to be exceedingly informative and has in most cases helped guys and women much like me to reach their dreams. This insightful help entails a lot to me and extremely more to my office colleagues. Many thanks; from each one of us.

  2. fear of god essentials hoodie

    I am commenting to let you be aware of what a terrific experience my cousin’s princess had viewing yuor web blog. She noticed so many things, not to mention what it’s like to possess an amazing helping nature to make many others with no trouble know some impossible subject areas. You truly exceeded my expected results. I appreciate you for distributing those precious, healthy, explanatory not to mention easy tips about this topic to Lizeth.

  3. giannis shoes

    I simply desired to appreciate you once again. I do not know the things I would’ve carried out without those concepts provided by you about such a topic. Certainly was the scary case for me, but encountering a new well-written fashion you handled that forced me to weep with contentment. Now i’m happier for your assistance and thus sincerely hope you find out what an amazing job you were getting into teaching some other people with the aid of your webpage. I am sure you have never encountered all of us.

  4. ggdb

    I simply wanted to send a small note so as to express gratitude to you for these great tactics you are posting on this site. My rather long internet research has at the end been paid with reputable content to share with my guests. I would say that we readers actually are unquestionably endowed to dwell in a decent network with so many awesome individuals with great suggestions. I feel rather lucky to have seen your entire web site and look forward to some more enjoyable times reading here. Thanks once more for a lot of things.

  5. jordan travis scott

    I happen to be writing to make you understand of the great discovery our girl experienced using yuor web blog. She figured out too many details, not to mention how it is like to possess an awesome giving mindset to make folks without problems completely grasp certain multifaceted topics. You truly exceeded our own desires. Thanks for showing those warm and helpful, safe, revealing and as well as easy tips about your topic to Janet.

  6. gap yeezy

    My wife and i were really more than happy when Louis managed to complete his preliminary research with the ideas he was given in your site. It’s not at all simplistic just to possibly be giving freely guides many people may have been trying to sell. So we keep in mind we have the writer to be grateful to for this. The specific explanations you made, the straightforward web site navigation, the friendships you will make it possible to instill – it’s many excellent, and it’s really assisting our son in addition to us understand that issue is fun, which is certainly particularly pressing. Thank you for the whole thing!

  7. kyrie shoes

    I want to get across my respect for your generosity in support of men who have the need for help with this question. Your personal dedication to passing the solution throughout turned out to be extremely advantageous and have regularly empowered girls much like me to get to their ambitions. Your personal interesting useful information implies much a person like me and still more to my colleagues. Thank you; from all of us.

  8. AgeseeDax

    cialis Materials and methods For this retrospective study, fifty consecutive patients who responded to CC were taken as Group 1, while fifty consecutive patients who failed to show adequate ovulatory response with CC were taken as Group 2

Laisser un commentaire

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