movie silent until button press, flash as3
Posted
by pixelGreaser
on Stack Overflow
See other posts from Stack Overflow
or by pixelGreaser
Published on 2010-04-02T20:34:06Z
Indexed on
2010/04/03
0:53 UTC
Read the original article
Hit count: 321
flash
|actionscript3
I thought I could change the Boolean true/false value, but it's not working. How do I get this to hush, until the button is pressed?
import flash.media.Sound;
import flash.media.SoundChannel;
var soundOn:Boolean = true; //music is ON when we start
var myToons:TitleMusic = new TitleMusic();
var myChannel:SoundChannel = myToons.play(0,1000); // endless loop, in effect
var myTransform:SoundTransform;
mySoundButton.addEventListener(MouseEvent.CLICK,toggleSound);
mySoundButton.buttonMode = true;
mySoundButton.mouseChildren = false;
function toggleSound(e:MouseEvent)
{
if(soundOn)
{
// turn sound off
myTransform = new SoundTransform();
myTransform.volume = 0; // silent
myChannel.soundTransform = myTransform;
soundOn = false;
mySoundButton.myButtonText.text = "click to turn sound ON";
}
else // sound is off
{
// turn sound on
myTransform = new SoundTransform();
myTransform.volume = 1; // full volume
myChannel.soundTransform = myTransform;
soundOn = true;
mySoundButton.myButtonText.text = "click to turn sound OFF";
}
}
© Stack Overflow or respective owner