/ Published in: ActionScript 3

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var myRequest:URLRequest = new URLRequest("/someDir/someFile"); var myLoader:Loader = new Loader(); myLoader.load(myRequest); myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader); myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress); myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showContent); var myPreloader:Preloader = new Preloader(); function showPreloader(event:Event):void { addChild(myPreloader); myPreloader.x = stage.stageWidth/2; myPreloader.y = stage.stageHeight/2; } function showProgress(event:ProgressEvent):void { var percentLoaded:Number = event.bytesLoaded/event.bytesTotal; myPreloader.loading_txt.text = "Loading - " + Math.round(percentLoaded * 100) + "%"; myPreloader.bar_mc.width = 198 * percentLoaded; } function showContent(event:Event):void { removeChild(myPreloader); addChild(myLoader); }
Comments
