This should get you started.
Here is how to communicate with a JSON service:
<mx:HTTPService id="service" resultFormat="text" url="http://json service url" result="onJSONLoad(event)" />
- id – Give the control a variable name so we can reference it later.
- url – the url that points to the JSON data we are loading
- resultFormat – the format that we want the data returned to us in. (In this case, just the raw text).
- result – event handler that is called when the data loads.
then to get the data:
import mx.rpc.events.ResultEvent;
import com.adobe.serialization.json.JSON;
private function onJSONLoad(event:ResultEvent):void
{
//get the raw JSON data and cast to String
var rawData:String = String(event.result);
//decode the data to ActionScript using the JSON API
//in this case, the JSON data is a serialize Array of Objects.
var arr:Array = (JSON.decode(rawData) as Array);
//do something with the Array
}
To Send Data:
<mx:HTTPService id="sendData" url="url of JSON service"
useProxy="false" method="GET" resultFormat="text"
result="updatedPHPDataResult(event)">
</mx:HTTPService>
And a UI element to trigger a send event
<mx:Button x="10" y="259" label="UpdateDatabase" id="butUpdate" click="{sendPHPData()}"/>
Now here is your ActionScript methods:
private function sendPHPData():void
{
var objSend:Object = new Object();
var dataString:String = JSON.encode(dataArray.toArray());
dataString = escape(dataString);
objSend.setTutorials = "true";
objSend.jsonSendData = dataString;
sendData.send(objSend);
}
And something to show it works
private function updatedPHPDataResult(event:ResultEvent):void
{
lblStatus.text = String(event.result);
}