Created
April 24, 2013 08:52
-
-
Save hrkd/5450714 to your computer and use it in GitHub Desktop.
jsonを読み込んで完了をコールバックするクラス
This file contains hidden or 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
package hrkd { | |
import flash.events.Event; | |
import flash.events.IOErrorEvent; | |
import flash.net.URLLoader; | |
import flash.net.URLRequest; | |
import com.adobe.serialization.json.JSON; | |
public class jsonloader { | |
private var myLoader; | |
private var _func:Function; | |
private var _errfunc:Function; | |
public var _result:Object; | |
public var resultErr:Object; | |
public function jsonloader(mf:String,f:Function,ef:Function):void { | |
// constructor code | |
_func = f; | |
_errfunc = ef; | |
myLoader = new URLLoader(); | |
myLoader.load(new URLRequest(mf)); | |
myLoader.addEventListener(Event.COMPLETE, completeHandler); | |
myLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); | |
} | |
private function completeHandler(event:Event):void { | |
myLoader.removeEventListener(Event.COMPLETE, completeHandler); | |
myLoader.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); | |
_result = JSON.decode(event.target.data); | |
_func(); | |
} | |
private function ioErrorHandler(event:IOErrorEvent):void { | |
resultErr = event; | |
_errfunc(); | |
} | |
} | |
} | |
//var loader = new jsonloader('data/data.json', | |
// function(){ | |
// trace(loader._result); | |
// },function(){ | |
// trace(loader.resultErr) | |
// } | |
//); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment