flex加载外部swf文件_第1页
flex加载外部swf文件_第2页
flex加载外部swf文件_第3页
flex加载外部swf文件_第4页
flex加载外部swf文件_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论