from: flex 4.0 api
Loader 类可用于加载 SWF 文件或图像(JPG、PNG 或 GIF)文件。使用 load()
方法来启动加载。被加载的显示对象将作为 Loader 对象的子级添加
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLRequest;
import flash.system.System;
public class LoaderExample extends Sprite
{
private var url:String="a.png";
public function LoaderExample()
{
var loader:Loader=new Loader();
configureListeners(loader.contentLoaderInfo);
loader.addEventListener(MouseEvent.CLICK,clickHandler);
var request:URLRequest=new URLRequest(url);
loader.load(request);
loader.scaleX=0.5;
loader.scaleY=0.5
addChild(loader);
}
private function configureListeners(dispatcher:IEventDispatcher):void{
dispatcher.addEventListener(Event.OPEN,open); // 1. 首次加载图片时执行
dispatcher.addEventListener(ProgressEvent.PROGRESS,progress); // 2. 加载图片开始和过程中执行
dispatcher.addEventListener(Event.INIT,init); // 3. 加载完成后,先执行init,后httpstatus
dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,httpstatus);// 4. 不是本地加载才执行
dispatcher.addEventListener(Event.COMPLETE,complete); // 5. click时执行
dispatcher.addEventListener(Event.UNLOAD,unload); // 6. loader.unload时发生
dispatcher.addEventListener(IOErrorEvent.IO_ERROR,ioerror); // 7. 找不到文件
}
private function clickHandler(event:MouseEvent):void{
trace("clickhandler: " event);
var loader:Loader=Loader(event.target);
loader.unload();
}
private function init(event:Event):void{
trace("init :" event);
}
private function complete(event:Event):void{
trace("complete:" event);
}
private function open(event:Event):void{
trace("open:" event);
}
private function unload(event:Event):void{
trace("unload:" event);
}
private function httpstatus(event:HTTPStatusEvent):void{
trace("httpstatusevent:" event);
}
private function ioerror(event:IOErrorEvent):void{
trace("ioerror:" event);
}
private function progress(event:ProgressEvent):void{
trace("progress:" event);
}
}
}
阅读(1189) | 评论(0) | 转发(0) |