资源预览内容
第1页 / 共8页
第2页 / 共8页
第3页 / 共8页
第4页 / 共8页
第5页 / 共8页
第6页 / 共8页
第7页 / 共8页
第8页 / 共8页
亲,该文档总共8页全部预览完了,如果喜欢就下载吧!
资源描述
济南盛世动漫游戏影视专修学院 http:/www.ss-edu.orgflex 加载外部 swf 文件引自: http:/www.ss-edu.org/news/LT/188.html第一步:建立加载类CtmObjLoader,此类可以加载文件类型 图片文件或 swf 文件package import flash.display.DisplayObject;import flash.display.Loader;import flash.events.*;import flash.net.URLRequest;import mx.core.UIComponent;public class CtmObjLoader extends UIComponentprivate var ProgressHandle:Function=null;public var loader:Loader;public var _bLoaded:Boolean=false;public var _bShow:Boolean=true;/UrlRequest 加载的地址/progressHandle 加载中的处理过程/bShow 加载后是否显示出来 public function CtmObjLoader(UrlRequest:String=null,progressHandle:Function=null,bShow:Boolean=true)super();if(UrlRequest)LoadThis(UrlRequest,progressHandle,bShow);public function LoadThis(UrlRequest:String,progressHandle:Function=null,bShow:Boolean=true):voidRemoveChild();loader = new Loader();_bShow=bShow;ProgressHandle=progressHandle;configureListeners(loader.contentLoaderInfo);if(_bShow)addChild(loader);/如果需要显示,则 addchildvar request:URLRequest = new URLRequest(UrlRequest);loader.load(request); public function UnLoadThis():void济南盛世动漫游戏影视专修学院 http:/www.ss-edu.orgtryRemoveChild();this.parent.removeChild(this);catch(e:Error)/this=null; public function get content():DisplayObjectif(!_bLoaded)return null;return loader.content;public function RemoveChild():voidif(_bLoaded)tryDeleteListeners(loader.contentLoaderInfo);loader.unload();if(_bShow)removeChild(loader);loader=null;_bLoaded=false;catch(e:Error)throw new Error(Define ObjLoader Remove Error) private function configureListeners(dispatcher:IEventDispatcher):void dispatcher.addEventListener(Event.COMPLETE, completeHandler);dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);if(ProgressHandle!=null)dispatcher.addEventListener(ProgressEvent.PROGRESS, ProgressHandle);private function DeleteListeners(dispatcher:IEventDispatcher):void if(dispatcher.hasEventListener(Event.COMPLETE)dispatcher.removeEventListener(Event.COMPLETE, completeHandler);if(dispatcher.hasEventListener(HTTPStatusEvent.HTTP_STATUS)dispatcher.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);if(dispatcher.hasEventListener(IOErrorEvent.IO_ERROR)dispatcher.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);if(dispatcher.hasEventListener(ProgressEvent.PROGRESS)if(ProgressHandle!=null)dispatcher.removeEventListener(ProgressEvent.PROGRESS, ProgressHandle); 济南盛世动漫游戏影视专修学院 http:/www.ss-edu.orgprivate function completeHandler(event:Event):void this.width=loader.content.width;this.height=loader.content.height;_bLoaded=true; dispatchEvent(new Event(Event.COMPLETE);private function httpStatusHandler(event:HTTPStatusEvent):void dispatchEvent(new Event(HTTPStatusEvent.HTTP_STATUS);private function ioErrorHandler(event:IOErrorEvent):void dispatchEvent(new Event(IOErrorEvent.IO_ERROR);第二步:建立加载flash as3 swf 文件类/此类专提供 flash as3 swf 文件加载,flex swf 不需要,当然也可以写成一个类 ,我习惯这样package import flash.display.MovieClip;public class mySwfLoader extends CtmObjLoaderpublic function mySwfLoader(UrlRequest:String=null, progressHandle:Function=null, bShow:Boolean=true)super(UrlRequest, progressHandle, bShow);public function get movieClip():MovieClipif(!_bLoaded)return nullreturn content as MovieClip;第三步:建立 flex 主文件 1mainforflex.mxml加载 flex swf 外部文件用第四步:建立 flex swf 子文件flexchild.mxml济南盛世动漫游戏影视专修学院 http:/www.ss-edu.org运行试试,加载 flex swf 文件完成,下面讲加载 flash cs3 swf 文件吧第一步:建立 flex 主文件 1mainforflash.mxml加载 flash cs3 swf 外部文件用第二步:写 flash cs3 文件,这个不在行,我写了个简单的测试,通过 的,所以你就自己写吧可以调用 flash cs3 文件的函数,也可以监听他发来的事件
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号