我试图创建一个静音和取消静音按钮。我不希望任何播放/暂停按钮只是静音和取消静音。到目前为止,我创建的只是静音按钮,问题是我不知道如何制作一个静音按钮。我也希望静音图标在点击后将其外观更改为取消静音图标。非常感谢任何帮助,谢谢大家。(一些方面的评论或解释也会很好)
希望我不要求太多。这是我目前的代码
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 :(得分:0)
我们假设您的mute_btn
实例中有一个实例名称为muteIcon
的子图标,该图标的存在是您声音目前是否已取消静音的可视指示(如一个带有斜线的圆圈,类型图标),下面是一个扬声器图标。
这将是代码:
//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:SoundChannel;
因为当你执行channel = sound.play();