Skip to content

Instantly share code, notes, and snippets.

@nuex
Created May 9, 2009 21:32
Show Gist options
  • Save nuex/109410 to your computer and use it in GitHub Desktop.
Save nuex/109410 to your computer and use it in GitHub Desktop.
jQuery-like getJSON function in ActionScript 3
/*
* jQuery-like getJSON function in ActionScript 3
*
* Used like:
*
* get_json('http://somehost.com/my.json', function(data) {
* trace(data);
* });
*
* Requires the AS3 Core Libraries: http://code.google.com/p/as3corelib/
*
*/
// get json from a url and execute a function when it completes
function get_json(url:String, on_complete:Function):void{
var request:URLRequest = new URLRequest();
request.url = url;
var loader:URLLoader = new URLLoader();
loader.load(request);
loader.addEventListener(Event.COMPLETE, function(e){
var loader:URLLoader = URLLoader(e.target);
var data:Array = JSON.decode(loader.data);
on_complete(data);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment