2015-05-25 93 views
0

我试图创建一个静音和取消静音按钮。我不想让任何播放/暂停按钮静音和取消静音。到目前为止,我所创建的只是静音按钮,问题是我不知道如何制作静音按钮。我还希望静音图标在点击后将其外观改为取消静音图标。任何帮助,非常感谢,谢谢大家。(一些意见或解释也会很好)静音和取消静音按钮as3闪光灯

希望我不要求太多。这里是我到目前为止的代码

var soundReq:URLRequest = new URLRequest("assets/for_flash.mp3"); 
var sound:Sound = new Sound(); 
var channel:SoundChannel = new SoundChannel(); 

sound.load(soundReq); 

sound.addEventListener(Event.COMPLETE, onComplete); 

    function onComplete (e:Event):void 
    { 
     sound.play(); 
    } 

mute_btn.addEventListener(MouseEvent.CLICK, muteSound); 

    function muteSound(e:MouseEvent):void 
    { 
     SoundMixer.stopAll(); 
    } 
+0

你的问题到底是什么?你不知道如何取消静音?你不知道如何切换图标? – BadFeelingAboutThis

+0

感谢您的回复!可悲的是它们都是。 –

回答

0

让我们在你的mute_btn例如假设,你必须与muteIcon实例名称和图标的存在一个孩子图标是你的声音是目前静音与否的视觉指示器(就像一个圆形斜杠穿过它键入图标),下面是一个扬声器图标。

这将是那么代码:因为创建一个

var channel:SoundChannel; 

//First, you need to assign the result of the sound.play function to the sound channel 
function onComplete (e:Event):void{ 
    channel = sound.play(); 
} 

mute_btn.addEventListener(MouseEvent.CLICK, muteBtnClick); 

function muteBtnClick(e:MouseEvent):void 
{ 
    //check to see if the sound channel exists yet (in case you click the button before the sound loads, otherwise you'll get an error 
    if(!channel) return; 

    //toggle the icon's visibility 
    mute_btn.muteIcon.visible = !mute_btn.muteIcon.visible; 

    //now check and see if the icon is visible or not 
    if(mute_btn.muteIcon.visible){ 
     //it is visible, so we should unmute the sound 
     channel.soundTransform = new SoundTransform(1); //1 is the volume level from 0 - 1 
    }else{ 
     //it is not visible, so we should mute the sound 
     channel.soundTransform = new SoundTransform(0); //0 is no volume, 1 is full volumn 
    } 
} 

此外,为了提高效率,你可以改变这一点:

var channel:SoundChannel = new SoundChannel(); 

对此该var中的新对象作为一个整体毫无意义当你做新的对象被分配channel = sound.play();

+0

您好LDMS真的很感谢您的帮助,特别是解释。我只是不明白如何添加子图标部分。我是否在mute_btn内创建另一个图层来添加取消静音图标?我这样做,但我得到一个错误“通过引用与静态类型flash.display:SimpleButton访问可能未定义的属性muteIcon。” 再次,非常感谢您的帮助! –

+0

是的,你打开你的静音按钮的时间轴,在时间轴上添加一个图标,并给它一个实例名称'muteIcon'。不过,您可能必须将其制作为MovieClip,因为我不知道SimpleButton是否支持时间轴儿童 - 这可能是您为什么会遇到错误。还有其他方法可以做到这一点,比如改变按钮或标签的颜色等。 – BadFeelingAboutThis