views:

21

answers:

2

I am using Flash Build Image control to load the image from outside using .source attribute, I want to add the percentage animation for the loading process of each image, just wondering how can I do that?

+1  A: 

Image docs are showing that Image is SWFLoader, and SWFLoader has ProgressEvent.PROGRESS event.

alxx
+1  A: 
private var loader:Loader;
private var request:URLRequest;

function loadImage() {

 loader=new Loader();
 request=new URLRequest(image_path);

 loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
 loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);

 loader.load(request);
}

function loadProgress(e:ProgressEvent):void {

 // The following variable holds the ratio of loaded bytes to total bytes
 // Use it to increase size, show percentage, etc

 var pct:Number = loader.contentLoaderInfo.bytesLoaded/loader.contentLoaderInfo.bytesTotal;

}

function loadComplete(e:Event):void {

 // Add all events that are to be fired after loading of the image

}

Call the loadImage function start the loading of the image.

loxxy