/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import flash.display.*; import flash.events.*; private function loadAsset(loadURL:String):void { var ldr:Loader = new Loader(); ldr.load(new URLRequest(loadURL)); ldr.contentLoaderInfo.addEventListener(Event.INIT, loadStart); ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); ldr.contentLoaderInfo.addEventListener(ErrorEvent.ERROR, loadError); ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadError); ldr.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError); } private function loadStart(e:Event):void { trace("load start"); ldr.contentLoaderInfo.removeEventListener(Event.INIT, loadStart); } private function loadError(e:Event):void { trace("load error"); ldr.contentLoaderInfo.removeEventListener(ErrorEvent.ERROR, loadError); ldr.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, loadError); ldr.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError); } private function loadComplete(e:Event):void { trace("load complete"); ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete); addChild(event.target.content) as MovieClip; }