免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1398 | 回复: 0
打印 上一主题 下一主题

flash.display.Loader [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:44 |只看该作者 |倒序浏览
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);
        }
    }
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP