Created
May 9, 2009 21:32
-
-
Save nuex/109410 to your computer and use it in GitHub Desktop.
jQuery-like getJSON function in ActionScript 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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