Actionscript – Unloading swf using the unloadAndStop() method, but video sounds remain audible

actionscriptactionscript-3flashflash-cs4

I have tried many approaches to unloading my swf, but to no avail, the video sounds within my laoded swf keep playing even once the swf has been loaded.

I have created a universal loader as follows:

var loader:Loader = new Loader();

I then load various swf's into a movie clip named mov_contentLoader, for example the video swf is loaded as follows:

loader.load(new URLRequest("video.swf")); //assign SWF url to loader
mov_contentLoader.addChild(loader); //add loaded content to movi clip

I then have a generic "exit" button, based on the state of the application, certain windows are closed, swf's are unloaded etc. For my video.swf file, when the exit button is clicked, I call the unloadAndStop(); method on the loader as follows:

loader.unloadAndStop(); //unload all content, do some garbage cleanup
mov_contentLoader.removeChildAt(0); //just to be safe, a second layer of reassurance ??

The SWF is unloaded, but for the life of me I can NOT get the sounds to stop! I even resorted to adding stage listeners on the video.swf to listen for an exiting state, but that still did not stop video sounds.

If I load the video.swf in again and play a different video, the two soundtracks play ontop of each other.

Any guidance, as always, is greatly accepted and appreciated.

Simon

Best Answer

The appropriate way to handle this is to program a destroy function into whatever loaded content you have, and then call it before you unload that content. In the destroy function the loaded swf should be responsible for its own business in regards to...

  • Stopping playing sounds.
  • Closing any open streams (like streaming video).
  • calling stop on its timelines
  • etc...

SoundMixer.stopAll() is in no way an appropriate solution. Rather, it can be if you are the one setting the parameters of what is "acceptable" as a jarring user experience, but if you are writing a 3rd party swf that is to be loaded into someone else's application you'll most certainly be responsible for cleaning up your own sound mess, and SoundMixer will kill not just your sounds, but the sounds from the loader, and that is one sure fire way to anger your hosts.

Related Topic