Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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
Actionscript 3 如何在as3中取消静音?_Actionscript 3_Flash Cs5 - Fatal编程技术网

Actionscript 3 如何在as3中取消静音?

Actionscript 3 如何在as3中取消静音?,actionscript-3,flash-cs5,Actionscript 3,Flash Cs5,对不起,我的英语不好。我有两个按钮的代码来静音和取消静音。当我单击静音时,它工作,但当我单击另一个按钮使声音播放时,它不工作。有什么帮助吗 import flash.media.SoundMixer; speakerb1.addEventListener(MouseEvent.CLICK, speaker2sound); speakerb2.addEventListener(MouseEvent.CLICK, speaker2sound); var channel2:SoundChannel

对不起,我的英语不好。我有两个按钮的代码来静音和取消静音。当我单击静音时,它工作,但当我单击另一个按钮使声音播放时,它不工作。有什么帮助吗

import flash.media.SoundMixer;

speakerb1.addEventListener(MouseEvent.CLICK, speaker2sound);
speakerb2.addEventListener(MouseEvent.CLICK, speaker2sound);
var channel2:SoundChannel = new SoundChannel();
var clicktoPlay:Boolean = true;


function speaker2sound(e:MouseEvent):void{
    if (clicktoPlay==true){
         var snd2:Sound = new Sound;
         snd2.load(new URLRequest("shakeup.wav"));
         clicktoPlay=false;
         channel2 = snd2.play();
         speakerb1.visible=true;
         speakerb2.visible=false;
         SoundMixer.soundTransform = new SoundTransform(1);
    }

    if (clicktoPlay==false){
         clicktoPlay=true;
         speakerb2.visible=true;
         speakerb1.visible=false;
         SoundMixer.soundTransform = new SoundTransform(0);
    }
    clicktoPlay =!clicktoPlay;
}

channel2.addEventListener(Event.SOUND_COMPLETE,soundfin);

function soundfin(event:Event):void{ 
    clicktoPlay=false; 
    speakerb1.visible=true;
    speakerb2.visible=false;
}

正如Marcela所说,试着去掉“clicktoPlay=!clicktoPlay;”这一行,看看它是否有效。
按照现在的代码方式,在调用“soundfin”之前,无论调用speaker2sound的频率有多高,clicktoPlay都将保持为true。

我对您的代码进行了一些小改动:

speakerb1.addEventListener(MouseEvent.CLICK, speaker2sound);
speakerb2.addEventListener(MouseEvent.CLICK, speaker2sound);
var channel2:SoundChannel = new SoundChannel();
var clicktoPlay:Boolean = true;
var snd2:Sound;

function speaker2sound(e:MouseEvent):void{
    if (clicktoPlay==true){
        if(!snd2){
            snd2 = new Sound();
            snd2.load(new URLRequest("Kalimba.mp3"));
            channel2 = snd2.play();
        }
        speakerb1.visible=true;
        speakerb2.visible=false;
        SoundMixer.soundTransform = new SoundTransform(1);
    }
    else {
        speakerb2.visible=true;
        speakerb1.visible=false;
        SoundMixer.soundTransform = new SoundTransform(0);
    }
    clicktoPlay =!clicktoPlay;
}

channel2.addEventListener(Event.SOUND_COMPLETE,soundfin);

function soundfin(event:Event):void{ 
    clicktoPlay=false; 
    speakerb1.visible=true;
    speakerb2.visible=false;
}

channel2.addEventListener(Event.SOUND_COMPLETE,soundfin);

function soundfin(event:Event):void{ 
    clicktoPlay=false; 
    speakerb1.visible=true;
    speakerb2.visible=false;
}

这可能与您正在使用
clicktoPlay
变量执行一些奇怪的操作有关。检查它是否为真,然后将其设置为假,然后检查它是否为假(它将始终为假,因为如果它最初为真,则将其设置为假)。然后,在所有这些之后,您将再次切换它。是的,但是当我再次单击并且它为false时,我将使ClickTopPlay为true。。