/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import flash.display.Loader; import flash.events.Event; import flash.events.ProgressEvent; import flash.events.IOErrorEvent; var myLoader = new Loader(); myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress); myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError); myLoader.load(new URLRequest("swfToLoad.swf")); function onProgress(evt:ProgressEvent):void { var nPercent:Number = Math.round((evt.bytesLoaded / evt.bytesTotal) * 100); loadingAnim.bar.scaleX = nPercent / 100; loadingAnim.percLoaded.text = nPercent.toString() + "%"; } function onComplete(evt:Event):void { myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress); myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete); addChild(myLoader); } function onIOError(evt:IOErrorEvent):void { trace("IOError loading SWF"); }