版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、济南盛世动漫游戏影视专修学院flex加载外部swf文件引自:/news/LT/188.html第一步:建立加载类CtmObjLoader,此类可以加载文件类型图片文件或swf文件packageimportflash.display.DisplayObject;importflash.display.Loader;importflash.events.*;.URLRequest;importmx.core.UIComponent;publicclassCtmObjLoaderextendsUIComponentpri
2、vatevarProgressHandle:Function=null;publicvarloader:Loader;publicvar_bLoaded:Boolean=false;publicvar_bShow:Boolean=true;UrlRequest加载的地址progressHandle加载中的处理过程/bShow加载后是否显示出来functionfunctionpublicCtmObjLoader(UrlRequest:String=null,progressHandle:Function=null,bShow:Boolean=true)super();if(UrlRequest)
3、LoadThis(UrlRequest,progressHandle,bShow);publicLoadThis(UrlRequest:String,progressHandle:Function=null,bShow:Boolean=true):voidRemoveChild();loader=newLoader();_bShow=bShow;ProgressHandle=progressHandle;configureListeners(loader.contentLoaderInfo);if(_bShow)addChild(loader);如果需要显示,则addchildvarreque
4、st:URLRequest=newURLRequest(UrlRequest);loaderoad(request);publicfunctionUnLoadThis():voidtryRemoveChild();this.parent.removeChild(this);catch(e:Error)/this=null;publicfunctiongetcontent():DisplayObjectif(!_bLoaded)returnnull;returnloader.content;publicfunctionRemoveChild():voidif(_bLoaded)tryDelete
5、Listeners(loader.contentLoaderInfo);loader.unload();if(_bShow)removeChild(loader);loader=nuII;_bLoaded=false;catch(e:Error)thrownewError('DefineObjLoaderRemoveError')privatefunctionconfigureListeners(dispatcher:IEventDispatcher):voiddispatcher.addEventListener(Event.COMPLETE,completeHandler)
6、;dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,httpStatusHandler);dispatcher.addEventListener(IOErrorEventO_ERROR,ioErrorHandler);if(ProgressHandle!=null)dispatcher.addEventListener(ProgressEvent.PROGRESS,ProgressHandle);privatefunctionDeleteListeners(dispatcher:IEventDispatcher):voidif(di
7、spatcher.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)dispat
8、cher.removeEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);if(dispatcher.hasEventListener(ProgressEvent.PROGRESS)if(ProgressHandle!=null)dispatcher.removeEventListener(ProgressEvent.PROGRESS,ProgressHandle);privatefunctioncompleteHandler(event:Event):voidthis.width=loader.content.width;this.heig
9、ht=loader.content.height;_bLoaded=true;dispatchEvent(newEvent(Event.COMPLETE);privatefunctionhttpStatusHandler(event:HTTPStatusEvent):voiddispatchEvent(newEvent(HTTPStatusEvent.HTTP_STATUS);privatefunctionioErrorHandler(event:IOErrorEvent):voiddispatchEvent(newEvent(IOErrorEventO_ERROR);第二步:建立加载flas
10、has3sw仗件类/此类专提供flashas3swf文件加载,flexswf不需要,当然也可以写成一个类,我习惯这样packageimportflash.display.MovieClip;publicclassmySwfLoaderextendsCtmObjLoaderpublicfunctionmySwfLoader(UrlRequest:String=null,progressHandle:Function=null,bShow:Boolean=true)super(UrlRequest,progressHandle,bShow);publicfunctiongetmovieClip()
11、:MovieClipif(!_bLoaded)returnnullreturncontentasMovieClip;第三步:建立flex主文件1mainforflex.mxml加载flexswf外部文件用<?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="xmlns:ns1="ManageView.*"fontSize="12"><mx:Script><!CDATAimportPackage.m
12、ySwfLoader;/*Flex控制加载外部的swf文件子文件为flex版*/importmx.managers.SystemManager;importmx.controls.Alert;importPackage.CtmObjLoader;importflash.utils.setTimeout;Bindableprivatevar_CtmObjLoader:mySwfLoader;privatevarLoadedSM:SystemManager;privatevarloadedMoiveClip:MovieClip;privatefunctionLoadSwf():voidLoaded
13、SM=null;loadedMoiveClip=null;if(_CtmObjLoader)_CtmObjLoader.LoadThis('flexchild.swf);/child.swf自己定义去吧else_CtmObjLoader=newmySwfLoader('flexchild.swf);_CtmObjLoader.addEventListener(IOErrorEventO_ERROR,OnFailHandle);_CtmObjLoader.addEventListener(Event.COMPLETE,OnCompleteHandle);this.addChild
14、(_CtmObjLoader);_CtmObjLoader.setStyle('horizontalCenter',0);_CtmObjLoader.setStyle('verticalCenter',0);privatefunctionOnFailHandle(e:Event):voidmx.controls.Alert.show('error');privatefunctionOnCompleteHandle(E:Event):voidLoadedSM=SystemManager(_CtmObjLoader.content);privatef
15、unctionOnTestCall(e:Event):voidAlert.show('ChildEventCall');privatefunctionMCtestCall():voidif(LoadedSM)trypublic函数LoadedSM.document.TestCall('FromParentCall');/TestCall为加载的文件catch(e:Error)Alert.show(e.message);elseAlert.show('请加载文件');return;privatefunctiontestAddChildListene
16、r():voidif(!_CtmObjLoader)tryLoadedSM.document.addEventListener("EventGoTOParent",OnTestCall);Alert.show('设置成功');catch(e:Error)></mx:Script><mx:Buttonlabel="加载flex子文件"click="LoadSwf();"x="26"y="10"/><mx:Buttonlabel="为加载
17、的文件设置Listener"click="testAddChildListener();"x="150"y="10"/><mx:Buttonlabel="测试加载的文件函数"click="MCtestCall();"x="342"y="10"/></mx:Application>第四步:建立flexswf子文件flexchild.mxml<?xmlversion="1.0"encoding=
18、"utf-8"?><mx:Applicationxmlns:mx="applicationComplete="initApp()"styleName="Border3"fontSize="12"><mx:Script><!CDATAimportmx.controls.Alert;privatefunctioninitApp():voidpublicfunctionTestCall(msg:String):voidmx.controls.Alert.show(msg);p
19、rivatefunctionEventGoToParent():voiddispatchEvent(newEvent('EventGoTOParent');></mx:Script><mx:Buttonx="327"y="148"label="向Parent通知事件”click="EventGoToParent()"/></mx:Application>运行试试,加载flexswf文件完成,下面讲加载flashcs3sw文件吧第一步:建立flex主文件1mainfor
20、flash.mxml加载flashcs3swf外部文件用<?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="xmlns:ns1="ManageView.*"fontSize="12"><mx:Script><!CDATA/*Flex控制加载外部的swf文件子文件为flashcs3版*/importmx.controls.Alert;importPackage.mySwfLoader;import
21、flash.utils.setTimeout;Bindableprivatevar_mySwfLoader:mySwfLoader;privatevarLoadedSM:MovieClip;privatefunctionLoadSwf():voidif(_mySwfLoader)_mySwfLoader.LoadThis('flashchild.swf);/flashchild.swf你自己去写了,我不太会,但我做了一个简单的,可用的else_mySwfLoader=newmySwfLoader('flashchild.swf);_mySwfLoader.addEventLis
22、tener(IOErrorEventO_ERROR,0nFailHandle);_mySwfLoader.addEventListener(Event.COMPLETE,OnCompleteHandle);this.addChild(_mySwfLoader);_mySwfLoader.setStyle('horizontalCenter',0);_mySwfLoader.setStyle('verticalCenter',0);privatefunctionOnFailHandle(e:Event):voidmx.controls.Alert.show(
23、9;error');privatefunctionOnCompleteHandle(E:Event):voidif(一mySwfLoader.content)Alert.show('okO');tryLoadedSM=_mySwfLoader.movieClip;catch(e:Error)privatefunctionOnTestCall(e:Event):voidAlert.show('ChildEventCall');privatefunctiongotoAndPlay(frame:int=0):void(_CtmObjLoader.loader.
24、contentasMovieClip).if(LoadedSM)tryLoadedSM.gotoAndPlay(frame);catch(e:Error)Alert.show(e.message);elseAlert.show('请加载文件');return;privatefunctionstop():voidif(LoadedSM)tryLoadedSM.stop();catch(e:Error)Alert.show(e.message);elseAlert.show('请加载文件');return;privatefunctionplay():voidif(LoadedSM)tryLoadedSM.play();catch(e:Error)Alert.show(e.message);elseAlert.show('请加载文件');return;pri
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工厂电路课程设计
- 工厂供电配电课程设计
- 工作分配问题课程设计
- 工业物联网培训课程设计
- 工业厂房设计课程设计
- 川大历史学课程设计
- 崇左陶土板幕墙施工方案
- 5.1 认识二元一次方程组 八年级数学北师大版上册课时优化训练(含答案)
- 岳西别墅施工方案
- 岩棉夹芯板施工方案
- 塔斯汀供应链分析
- 2024年01月广东省阳春市退役军人事务局2024年公开招考3名政府购买服务工作人员笔试历年高频考题(难、易错点荟萃)答案带详解附后
- 2024年汽车行业市场竞争态势分析
- 本科审核评估自评报告
- TNAHIEM 101-2023 急诊科建设与设备配置标准
- 网络安全数据保护培训
- 气管插管病人意外拔管应急预案护理课件
- 2024年天翼云运维工程师认证考试复习题库(含答案)
- 巨量广告投放培训课件
- 机械岗位专业知识
- 语文学习任务群的解读
评论
0/150
提交评论