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;
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("swfonLoad.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");
}
In additional, here is another simple clip which introduce How to track load progress with ActionScript in Adobe Flash Professional CS5.

February 11th, 2011
Ntt.cc
Posted in
Tags: 
RSS Feed
Email Feed