|
I'm pretty tired so I'll keep this simple. Best way I have found to ensure that an audio stream is destroyed and the memory returned when you stop it:
private var mySound:Sound = new Sound(); private var audio:SoundChannel = new SoundChannel(); private function startPlaying():void{ mySound = new Sound(new URLRequest("music/sample.mp3")); mySound.addEventListener(Event.COMPLETE, completeSound); audio = mySound.play(); } private function stopPlaying():void{ audio.stop(); mySound.removeEventListener(Event.COMPLETE,completeSound); mySound = null; }Trick is to declare the variables outside the function, ensure you configure a sound channel (audio) for your sound, and make sure you that you can reference both from the stop function. Then you need to stop the audio, remove any event listeners, and set sound to null. I found it's also a good idea to do your URLRequest inline, as it seems to get destroyed at the same time as mySound.