Flash Actionscript 3.0中的闪烁静音按钮不';t取消静音
我对Actionscript非常陌生,但我遵循了一个创建静音按钮的教程,该按钮可以很好地静音我的音频,但不会在之后再次取消静音。我的代码怎么了Flash Actionscript 3.0中的闪烁静音按钮不';t取消静音,flash,actionscript,Flash,Actionscript,我对Actionscript非常陌生,但我遵循了一个创建静音按钮的教程,该按钮可以很好地静音我的音频,但不会在之后再次取消静音。我的代码怎么了 function setMute(vol){ sTransform.volume = vol; SoundMixer.soundTransform = sTransform; } var sTransform:SoundTransform = new SoundTransform(1,0); var Mute:Boolean = fa
function setMute(vol){
sTransform.volume = vol;
SoundMixer.soundTransform = sTransform;
}
var sTransform:SoundTransform = new SoundTransform(1,0);
var Mute:Boolean = false;
themutebutton.addEventListener(MouseEvent.CLICK,toggleMuteBtn);
function toggleMuteBtn(event:Event) {
if(Mute === false) {
Mute = true;
setMute(0);
} else {
Mute = false;
setMute(1);
}
}
您应该使用
声音
类:
public class YourClass extends Sprite
{
// declare the member variables
private var yourSound:Sound = new Sound();
private var muted:Boolean = false;
private function initializationMethod()
{
yourSound.load(new URLRequest("yourSound.mp3"));
yourSound.addEventListener(IOErrorEvent.IO_ERROR, yourSoundErrorHandler);
yourSound.play();
muteButton.addEventListener(MouseEvent.CLICK, muteButtonClickHandler);
this.addChild(muteButton);
}
private function muteButtonClickHandler(event:MouseEvent):void
{
if ( muted )
{
muted = false;
yourSound.play();
// you might want to change the button text or image here
}
else
{
muted = true;
SoundMixer.stopAll();
// you might want to change the button text or image here
}
}
您可以尝试通过以下方式重写函数:
function setMute(vol){
SoundMixer.soundTransform = new SoundTransform(vol);
}
我在一个愉快的生产项目中发现它是这样工作的 感谢您的回答,问题实际上是var mute被初始化为false。我取下了=false,它解决了我的问题 对于初学者来说,这门课有点复杂,伊戈尔·米拉的答案很有效,但前提是我去掉了=假