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...
Up vote 0 down vote favorite share g+ share fb share tw.
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 flash actionscript-3 actionscript flash-cs4 link|improve this question asked Feb 16 '11 at 8:06One Stuck Pixel725214 63% accept rate.
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.
1 for being correct. Unfortunately, unload() and unloadAndStop() do not work for anything that has been created by ActionScript. You will always have to take care of cleaning up your code, otherwise you will bloat memory usage and sooner or later experience weird glitches due to zombie code still running somewhere hidden in your program.
– weltraumpirat Feb 16 '11 at 15:19 @scriptocalypse many thanks for your reply. As this is not for third party use and will never be integrated into another flash application, I am not too concerned about using the SoundMixer.stopAll(); function. Onto your point RE a destroy function.
How would one target video WITHIN the loaded swf from WITHIN the loader itself? That is for the most part my biggest challenge, hence why I resorted to the SoundMixer option. Thank you.
– One Stuck Pixel Feb 17 '11 at 6:35 @weltraumpirat - quote: "unload() and unloadAndStop() do not work for anything that has been created by ActionScript". That is untrue. Unload() does not, it simply removes the loaded instance, but unloadAndStop() is designed exactly for the purpose of cleaning up "most" things (events, listeners etc) created by actionscript.
– One Stuck Pixel Feb 17 '11 at 6:37 1 @webfac: My experience is that unloadAndStop() is at least unreliable, if not flawed. Just Google for "unloadandstop not working" and you'll find tons of forum threads having similar problems. It might be intended to do those things, and it might work for simple programs, but it isn't a solution I would choose over having my own destroy() methods.
– weltraumpirat Feb 17 '11 at 8:11 1 @webfac the destroy function would be declared as a member of the loaded swf. In order to call functions on that loaded swf you'd do so by either calling loader.content.destroy(); or storing loader. Content in a local variable in the swf that does the loading and call destroy from there.
– scriptocalypse Feb 17 '11 at 14:53.
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.
Would be nice to see if this was reported bug to Adobe. – cupuyc Dec 12 '11 at 14:38.
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.
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(); }.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.