2012-02-29 82 views
0

我對Actionscript非常陌生,但是我遵循了一個關於創建靜音按鈕的教程,該按鈕可以很好地靜音我的音頻,但不會在之後再次取消靜音。我的代碼有什麼問題?Actionscript 3.0中的Flash靜音按鈕不會取消靜音

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

回答

0

感謝您的答案,問題實際上是無聲靜音被初始化爲false。我取下了= false,它解決了我的問題。

這個班對我來說有點複雜,作爲一個初學者,來自伊戈爾米拉的答案只有當我把= false帶走

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

你可以嘗試重寫你的函數是這樣的:

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

,我發現它的工作像這樣在我愉快地工作一個在生產項目中。