Skip to main content
somascope
Inspiring
December 13, 2007
Question

Loading SWF with audio playing in it...

  • December 13, 2007
  • 8 replies
  • 1174 views
I was loading a SWF file, and noticed that even if I didn't add it to the display via addChild() that I can hear the audio playing in it. Why is this? And likewise, when I do addChild(), and see the SWF, then later use removeChild(), and no longer see it, I can still hear it playing.

I can sort of understand that even though it's not displayed until using addChild() that one would HEAR it, because it is loaded - correct? But how would I actually get rid of/delete this when I no longer want to see/hear it ?
This topic has been closed for replies.

8 replies

kglad
Community Expert
Community Expert
December 14, 2007
yes, stopping the timeline is no problem. and yes, this isn't very convenient and it does severely restrict as3 collaboration among different authors.
somascope
somascopeAuthor
Inspiring
December 14, 2007
Good note!

I used the stopAll() method, which did the trick:
SoundMixer.stopAll();

And that stops it, but sadly - because the SWF loaded is playing timeline audio (which is a looping SWF, audio restarts at the beginning with no stop() at end), the audio begins anew. Ugh.

However, using the method above where you can make a reference to the loaded SWF, I am able to stop that SWF's timeline when I removeChild and then show new content on the timeline. What an awkward thing...
kglad
Community Expert
Community Expert
December 14, 2007
i think you'll have to stop all sounds then. the soundmixer class has a stopAll() method that works like the as2 stopAllSounds() function.
kglad
Community Expert
Community Expert
December 14, 2007
well, loading swfs is not unlike opening email attachments. if you don't know what's in there and how to deal with it, you shouldn't do either.
somascope
somascopeAuthor
Inspiring
December 14, 2007
Good analogy, kglad, but I do know tha tsome of the files I'll be loading will have timeline streaming audio - so I will have to account for that.
somascope
somascopeAuthor
Inspiring
December 13, 2007
I saw that, too, about closing the streams. However, I don't understand how I'd use that when the sound is a timeline sound embedded in the loaded SWF file (as either streaming or event audio).
kglad
Community Expert
Community Expert
December 13, 2007
unfortunately, there's not way to write a class or function that will close all streams. you must know the names of the open streams. the flash help files give an example:

function closeAllStreams(evt:Event) {
myNetStream.close();
mySound.close();
myNetConnection.close();
myLocalConnection.close();
}


but this isn't helpful unless you know the names of those streams.
kglad
Community Expert
Community Expert
December 13, 2007
you must stop all streams, including sound to get them to stop. even unloading/nulling/and forcing gc will not stop open streams.
Known Participant
December 13, 2007
The only way I could make the audio stop was to use the content property and the stop method.

I don't have the exact code in front of me right now but, if you need it, just let me know and I post it later in another reply.
somascope
somascopeAuthor
Inspiring
December 13, 2007
I would be curious what you did - thanks! This was regardless of how the audio was controlled (event o streaming on timeline, or a Sound object).

This seems like somthing that we'd all have to worry about, doesn't it? I might not know what is in the SWF being loaded, and I don't want to have to worry about it still playing when I remove it from the display list.

Are there (proper) ways to unload a SWF - remove it and know it's actually no longer there?
Known Participant
December 13, 2007
I do four things when unloading/removing a loaded in swf

If the file is in the middle of loading in, I use the close() method to stop the stream.

In addition, I use the unload() method, the removeChild() method, and I also use the stop() method. Without the stop() method, the audio will continue playing. It seems it would stop with using unload and removeChild but I guess even if you do those two methods, that the displayList won't be cleared of it until the garbage collector comes around. It seems to me that the garbage collector would remove it as soon as removeChild runs, but it doesn't.

I'll post my content/stop code later this evening. I don't have the file with me and can't remember the exact code off the top of my head.