對不起,我的英文..我有一個代碼爲兩個按鈕來靜音和取消靜音聲音..當我點擊靜音的聲音,它的作品,但當我點擊另一個按鈕,使聲音播放它不工作..任何幫助?如何解除as3中的聲音?
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;
}
它可能有一些做的事實,你正在做一些奇怪的東西你'clicktoPlay'變量。你檢查它是否爲真,然後將它設置爲false,然後檢查它是否是假的(它總是會是的,因爲如果它最初是真的,你將它設置爲假)。然後,所有這一切,你再次切換。 – Marcela
是的,但當我再次點擊,它是假的,然後我讓clicktoPlay真正.. – Domna