April 5, 2008
WikiUsing JSON with as3
#wiki
In order to use JSON support in as3, you have to download as3corelib. After this, it’s pretty straightforward in Flex Builder.
package {
import com.adobe.serialization.json.JSON;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class JSONExample extends Sprite
{
private var theFileContent:String;
private var theObj:Object;
public function JSONExample()
{
var url:String = "some url";
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(url);
loader.load(request);
loader.addEventListener(Event.COMPLETE, completeHandler);
}
private function completeHandler(e:Event):void {
trace(e.target.data);
var theObj:Object = JSON.decode(e.target.data);
//trace(theObj.totalResultsAvailable);
for ( var i in theObj ) {
trace( i );
}
trace(theObj.ResultSet.totalResultsAvailable);
}
}
}
sources
*Mike Chamber’s Blog *JSON and AS3 URLRequest Class *Using JSON with Yahoo! Web Services FIXME (add the notation content here.) *JSON - JavaScript Object Notation
Continue Reading
Back to Archive