AS3 Track Loader Progress


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import flash.display.Loader;
  2. import flash.events.Event;
  3. import flash.events.ProgressEvent;
  4. import flash.events.IOErrorEvent;
  5.  
  6. var myLoader = new Loader();
  7.  
  8. myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
  9. myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
  10. myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
  11.  
  12. myLoader.load(new URLRequest("swfToLoad.swf"));
  13.  
  14. function onProgress(evt:ProgressEvent):void {
  15. var nPercent:Number = Math.round((evt.bytesLoaded / evt.bytesTotal) * 100);
  16. loadingAnim.bar.scaleX = nPercent / 100;
  17. loadingAnim.percLoaded.text = nPercent.toString() + "%";
  18. }
  19.  
  20. function onComplete(evt:Event):void {
  21. myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
  22. myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
  23. addChild(myLoader);
  24. }
  25.  
  26. function onIOError(evt:IOErrorEvent):void {
  27. trace("IOError loading SWF");
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.