Actionscript 3.0中的Flash静音按钮不会取消静音

时间:2012-02-29 12:31:37

标签: flash actionscript

我对Actionscript非常陌生,但我遵循了一个关于创建静音按钮的教程,该按钮可以很好地静音我的音频但不能在之后再次取消静音。我的代码出了什么问题?

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);
    }
}

3 个答案:

答案 0 :(得分:0)

您应该使用Sound课程:

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
        }
    }

答案 1 :(得分:0)

您可以尝试以这种方式重写您的功能:

function setMute(vol){   
   SoundMixer.soundTransform = new SoundTransform(vol);
}

我发现它在我的一个生产项目中愉快地工作,就像这样工作。

答案 2 :(得分:0)

感谢您的回答,问题实际上是默认初始化为false。我脱掉了= false,它解决了我的问题。

作为一名初学者,这堂课对我来说有点复杂,而igor milla的回答是有效的,但只有当我接受=假的时候