How To Track Loader Progress in AS3


We introduced three ways to load an image file in Flex in previous article. Normally there are no any problem with loading progress of external files. You can add an event listen(Event.COMPLETE) to monitor if it is complete then do something, but if you also want to do something when any errors were caused on the loading, what should we do? Below is the sample source code on how to track Loader process in AS3:



import flash.display.Loader;





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(“swfonLoad.swf”));


function onProgress(evt:ProgressEvent):void {


var nPercent:Number = Math.round((evt.bytesLoaded / evt.bytesTotal) * 100); = 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”);