Tuesday, November 17, 2009

Mute Streaming Audio in Flash

Muting sounds that are streaming in Flash isn't as simple as changing the volume of an object via a "mute" button. But it is surprisingly EASY! I can't believe I didn't see it. AND the movie continues to play and unmuting just brings the sound back in.... duh!

Well, I searched and searched and finally found something. Thanks (http://www.actionscript.org/forums/showthread.php3?t=32982)! I made some simple modifications.

This is my code. I made a MC with 2 frames and buttons in it. In frame 1, a button that calls "mute();" here's the button code for the one that's in frame 1.

on (release) {
nextFrame();
this._parent.mute();
}
And frame 2 has this:

on(release) {
prevFrame();
this._parent.unmute();
}

And here's the code in the root. I could easily make a volume slider that sets the "level" variable, and would then set. But for most stuff, we simply need the sound to be either there... or not.

level = 100;
globalSound = new Sound();
globalSound.setVolume(level);

function mute() {
trace("mute");
//previewaudio.stop();
globalSound.setVolume(0);
}
function unmute() {
trace("unmute");
globalSound.setVolume(100);
}

Enjoy!