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
The eventlistener that listens for the Event.UNLOAD and then calls the function which pulls out the 'SoundMixer.stopAll()' function is a decent workaround. This doesn't work if you are loading your swf from another domain than the one your container swf is on. I'm pretty sure it triggers a sandbox violation. I do not have a solution for that - and the best solution anyway is the one mentioned above, mentioned by scriptocalypse.
But I'm in a situation where I am on different domains AND I have no control over the SWF files - so I can't put 'destroy' functions into them. I'm going crazy.
After much research I have solved this problem. In the hope that this will make someone's life a lot easier, here was the issue:
The unloadAndStop();
method removes any event listeners, instances, objects etc from the loaded SWF. In my case I had videos, and IF the video was still playing when the user exited (and the loaded unloaded the content) the sounds would carry on. It seems that one thing the unloadAndStop();
function does NOT do is stop all sounds.
The solution? I attached an event listener to my loader, and after the content was successfully UNLOADED, I called the SoundMixer.stopAll();
function which ensured no sounds carried on playing! This DOES however mean that if you had ambient background sounds all along, they would stop too. You could go even further and get the current time of your ambient sounds and simply "restart" them immediately from that point in time.
My simple vent listener looks like this:
myloader.contentLoaderInfo.addEventListener(Event.UNLOAD, cleanUp);
function cleanUp(e:Event):void{
SoundMixer.stopAll(); //stop all sounds...
}
I trust this will help someone! It's a little "hacky" but it does the job just fine.
Kind regards, Simon
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...
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.
In your video.swf
, you have to write something like this:
this.addEventListener(Event.REMOVED_FROM_STAGE, stopSound)
function stopSound(e:Event):void
{
my_flvPlayer.stop();
}