2010-09-27 101 views
0

我正在使用Flash Build Image控件从外部使用.source属性加载图像,我想为每个图像的加载过程添加百分比动画,只是想知道我该怎么做?如何做图像加载动画?

回答

1

Image docs显示Image是SWFLoader,而SWFLoader有ProgressEvent.PROGRESS事件。

1
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 

} 

调用loadImage函数开始加载图像。