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/30/4037090.aspx
Pioneering little turtle -------> csdn
Today, a SwF with sound is loaded, and then another SWF is loaded when the playback is not completed. It is also a sound, and strange things have emerged, previously, the SWF video was destroyed and the unload was lost, but the sound was still playing and the memory was not released, it takes a long time to release (if the playback is complete or everything in my code is destroyed, but I am a little confused about the garbage collection mechanism of ActionScript 3, still thinking ....), The harmful PM waited for me for a long time.
First, let's talk about the sound. In fact, I didn't pay attention to it before. I found it today. Later I checked Adobe docs and found it very easy. Let's first look at flash in Adobe docs. media. sound class description:
Especially when it is marked with a red line, it tells us to control the externally loaded SWF file and use the soundmixer class attribute. OK. After looking at the soundmixer class, we found it very simple. This class provides a static method stopall to stop the currently playing sound. Take a look:
Okay, modify the class (http://blog.csdn.net/li_007/archive/2009/03/28/4032276.aspx) that was posted in the previous article as follows:
// <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/> // copyright @ luxoom.cn <br/> // last modified by leezhm on 30th March, 2009 <br/> // </P> <p> package SRCS <br/> {<br/> Import flash. display. displayobjectcontainer; <br/> Import flash. display. loader; <br/> Import flash. displ Ay. movieclip; <br/> Import flash. display. loaderinfo; <br/> Import flash. events. event; <br/> Import flash. events. mouseevent; <br/> Import flash.net. URLRequest; </P> <p> Import flash. media. soundmixer; </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 Function 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/>}< br/> else <br/>{< br/> return NULL; <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/> This. _ loader. addeventlistener (mouseevent. click, Onloaderclick); <br/>}</P> <p> private function onloaderenterframe (EVT: event = NULL ): void <br/>{< br/> If (null! = This. _ currentmc & <br/> movi((evt.tar get ). currentframe = This. _ currentmc. totalframes) <br/>{< br/> soundmixer. stopall (); </P> <p> This. _ currentmc = NULL; </P> <p> If (null! = This. _ Request) <br/>{< br/> This. _ Request = NULL; <br/>}</P> <p> If (null! = This. _ loader) <br/>{< br/> This. _ loader. removeeventlistener (mouseevent. click, onloaderclick); </P> <p> 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. removeeventlistener (event. enter_frame, onloaderenterframe); <br/>}</P> <p> PR Ivate function onloaderclick (EVT: mouseevent = NULL): void <br/>{< br/> soundmixer. stopall (); </P> <p> This. _ currentmc = NULL; </P> <p> If (null! = This. _ Request) <br/>{< br/> This. _ Request = NULL; <br/>}</P> <p> If (null! = This. _ loader) <br/>{< br/> This. _ loader. removeeventlistener (mouseevent. click, onloaderclick); </P> <p> 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. removeeventlistener (event. enter_frame, onloaderenterframe); <br/>}</P> <p>}
Test, can keep up with the requirements, achieve control, OK, success, go home .......
We need to take a closer look at the issue of memory release and share it with you.