Stopping sounds in Flash AS3

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]

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>