まぁ使い方を考えると、それぞれ別でもイイ気がしてきたので、別で。
基本はHttpServerと同じ。内部でLoaderクラスを呼ぶだけ。
Httpのときと同じように、ひとつずつ動作させる。
こんな感じで。
// ------------------------------------------------------------------------------ function spLoadImage(){ own = this; init(); } // ------------------------------------------------------------------------------ public function ldInit(e:Event):void{ trace(e); } // ------------------------------------------------------------------------------ public static function getEnum(n:int):String{ switch(n){ case eNotBitmap: return "Not Bitmap Resource"; case eIOError: return "IO Error"; case eSecurityError: return "Securit Error"; default: return "Undifiend Error"; } } // ------------------------------------------------------------------------------ private function ldComplete(e:Event):void{ trace(e); if(loader.content is Bitmap){ var lp:Object = loader.content; // var lp:Bitmapだとエラー var bit:Bitmap = new Bitmap(lp.bitmapData.clone()); lp.bitmapData.dispose(); okFunction(localVal,bit); }else{ ngFunction(eNotBitmap, getEnum(eNotBitmap)); } nextGo(); } // ------------------------------------------------------------------------------ private function ldIOError(e:IOErrorEvent):void{ ngFunction(eIOError,e.text); nextGo(); } // ------------------------------------------------------------------------------ private function nextGo():void{ trace("--nextGo--"); loader.contentLoaderInfo.removeEventListener(Event.INIT, ldInit); loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, ldComplete); loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ldIOError); bRun = false; execute(); } // ------------------------------------------------------------------------------ private function init():void{ uVar = new URLVariables; datAr = new Array; } // ------------------------------------------------------------------------------ public function setData(url:String, comtype:uint, okRes:Function, ngRes:Function, args:String,method:String="POST"):void{ datAr.unshift( { "url": url, "comtype": comtype, "okFunc": okRes, "ngFunc": ngRes, "args": args, "method": method } ); // Array // pop() 最後を取り出して削除 // unshift(... args):uint 最初に追加 } // ------------------------------------------------------------------------------ public function execute():void{ setTimeout(executeSub, tInterval); } // ------------------------------------------------------------------------------ private function executeSub():void{ if(datAr.length < 1){ // END }else{ if(bRun){ setTimeout(executeSub, tInterval); }else{ trace("☆executeSub "+datAr.length); bRun = true; var o:Object = datAr.pop(); loader = new Loader; loader.contentLoaderInfo.addEventListener(Event.INIT, ldInit); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ldComplete); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ldIOError); var UR:URLRequest = new URLRequest(o.url); if(o.method == "GET") UR.method = URLRequestMethod.GET; else UR.method = URLRequestMethod.POST; uVar = new URLVariables; // 何か設定することになるだろう。 uVar.args = o.args; UR.data=uVar; // okFunction = o.okFunc; ngFunction = o.ngFunc; localVal = o.comtype; try{ loader.load(UR); } catch (error:SecurityError){ // err:Error ngFunction(eSecurityError,getEnum(eSecurityError)); } } } } // ------------------------------------------------------------------------------