Stopping sounds in Flash AS3
Posted on Dec 30, 2009
For some reason I always have a little bit of a mental block on controlling sounds in Flash. So I’m posting so I can find it myself.
I had this issue with a client website. There is an intro that automatically plays and a “skip intro” button that should stop the sound of the intro. There may be a better way but this worked for me.
When you have sound in AS3 from an external source that doesn’t have media controls you may need a button for a mute/unmute. Here is some basic code to start your buttons.
//playBtn and pauseBtn are two basic buttons
playBtn.addEventListener(MouseEvent.CLICK, playSound);
pauseBtn.addEventListener(MouseEvent.CLICK, pauseSound);
function playSound(event:MouseEvent):void{
SoundMixer.soundTransform = new SoundTransform(1); //This will unmute all sound from SWF.
}
function pauseSound(event:MouseEvent):void{
SoundMixer.soundTransform = new SoundTransform(0); //This will mute all sound from SWF.
}
You can add a SoundMixer.stopAll(); to buttons leaving the frame/movie if you want to stop all the sounds completely.

![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_b.png?x-id=1d65f44c-0164-42b1-966e-1cbca20e0d7a)








