A simple File class for loading external SWF files

Source: Internet
Author: User

Disclaimer: Anyone and organizations are welcome to repost the articles in this blog, but the original links and author information must be marked.

Link: http://blog.csdn.net/li_007/archive/2009/03/28/4032276.aspx

Pioneering little turtle -------> csdn

 

Next to my previous blog post a SwF class that I usually use to load avm2 and share it with everyone.

// <Br/> // cloadmedia. as <br/> // you can load external SWF and pictures used this class <br/> // written by leezhm, 7th Nov, 2008 <br/> // contact: Leezhm@126.com <br/> // last modified by leezhm on 7th Nov, 2009 <br/> // </P> <p> package SRCS <br/> {<br/> Import flash. display. displayobjectcontainer; <br/> Import flash. display. loader; <br/> Import flash. display. movieclip; <br/> Import flash. d Isplay. loaderinfo; <br/> Import flash. events. event; <br/> Import flash.net. URLRequest; </P> <p> public class cloadmedia <br/> {<br/> private VaR _ file: String = ""; <br/> private VaR _ Loader: loader; <br/> private VaR _ Request: URLRequest; </P> <p> private VaR _ display: displayobjectcontainer; </P> <p> private VaR _ currentmc: movieclip; </P> <p> Public static const video_is_over: String = "videoisover"; </P> <p> Public fun Ction cloadmedia (STR: String, DIS: displayobjectcontainer) <br/>{< br/> If (""! = Str) <br/>{< br/> This. _ file = STR; <br/>}< br/> else <br/>{< br/> trace ("the path of extern file is null !!! "); <Br/>}</P> <p> If (null! = Dis) <br/>{< br/> This. _ display = DIS; <br/>}</P> <p> public function loading (): void <br/> {<br/> If (null = This. _ Request) <br/>{< br/> This. _ Request = new URLRequest (this. _ file); <br/>}</P> <p> If (null = This. _ loader) <br/>{< br/> This. _ loader = new loader (); <br/>}</P> <p> This. _ loader. load (this. _ request); </P> <p> This. _ loader. contentloaderinfo. addeventlistener (event. init, oncontentinit); </P> <p> This. _ display. addchild (this. _ loader); <br/>}</P> <p> Public Function get currentmovieclip (): movieclip <br/>{< br/> If (null! = This. _ currentmc) <br/>{< br/> return this. _ currentmc; <br/>}</P> <p> private function oncontentinit (EVT: event = NULL ): void <br/>{< br/> This. _ loader. contentloaderinfo. removeeventlistener (event. init, oncontentinit); </P> <p> If (3 = evt.tar get. actionscriptversion) <br/>{< br/> evt.tar get. addeventlistener (event. complete, onloadcompleted); <br/>}< br/> else <br/>{< br/> trace ("The ActionScript version Of SWF file is incorrect !!! "); <Br/>}</P> <p> private function onloadcompleted (EVT: event = NULL ): void <br/>{< br/> This. _ display. visible = true; </P> <p> This. _ loader. contentloaderinfo. removeeventlistener (event. complete, onloadcompleted); </P> <p> This. _ currentmc = movi((evt.tar get. content); </P> <p> evt.tar get. content. addeventlistener (event. enter_frame, onloaderenterframe); <br/>}</P> <p> private function onloaderenterframe (EV T: event = NULL): void <br/>{< br/> If (movi((evt.tar get ). currentframe = This. _ currentmc. totalframes) <br/>{< br/> If (null! = This. _ Request) <br/>{< br/> This. _ Request = NULL; <br/>}</P> <p> If (null! = This. _ loader) <br/>{< br/> This. _ loader. dispatchevent (new event (cloadmedia. video_is_over); </P> <p> This. _ display. removechild (this. _ loader); <br/> This. _ display = NULL; </P> <p> This. _ loader. unload (); <br/> This. _ loader = NULL; <br/>}</P> <p> evt.tar get. addeventlistener (event. enter_frame, onloaderenterframe); <br/>}</P> <p>}

 

After the SWF file is played, A video_is_over event will be sent. Because _ loader is used to send the event, the event must be captured in the capture phase (event Stream Mechanism of ActionScript 3 ). The following is a simple application:

// <Br/> // luxflashenvironment. as <br/> // the entry of application <br/> // written by leezhm, 7th Nov, 2009 <br/> // contact: Leezhm@126.com <br/> // last modified by leezhm on 7th Nov, 2009 <br/> // </P> <p> package SRCS <br/>{</P> <p> Import flash. display. sprite; <br/> Import flash. events. event; </P> <p> public class luxflashenvironment extends sprite <br/> {<br/> private VaR _ loadmedia: cload Media; </P> <p> Public Function luxflashenvironment () <br/>{< br/> If (stage) <br/>{< br/> initapplication (); <br/>}< br/> else <br/>{< br/> This. addeventlistener (event. added_to_stage, initapplication); <br/>}</P> <p> private function initapplication (EVT: event = NULL ): void <br/>{< br/> This. addeventlistener (cloadmedia. video_is_over, onvideoplayover, true); </P> <p> This. _ loadmedia = new cloadmedia ("Medi As // middle.swf ", this); <br/> This. _ loadmedia. loading (); <br/>}</P> <p> private function onvideoplayover (EVT: event = NULL ): void <br/>{< br/> If (null! = This. _ loadmedia) <br/>{< br/> This. _ loadmedia = NULL; <br/>}< br/>}

In cloadmedia class, we also implement the property currentmovieclip for converting the loaded SWF into a movieclip instance. With this property, we can operate the loaded external SWF file like movieclip.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.