2012-02-29 83 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); 
} 

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