Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash Actionscript 3.0中的闪烁静音按钮不';t取消静音_Flash_Actionscript - Fatal编程技术网

Flash Actionscript 3.0中的闪烁静音按钮不';t取消静音

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

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

您应该使用
声音
类:

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,它解决了我的问题

对于初学者来说,这门课有点复杂,伊戈尔·米拉的答案很有效,但前提是我去掉了=假