循环as3后的音量控制

时间:2015-05-15 14:11:33

标签: actionscript-3 flash

我的代码有问题。代码效果很好有一个例外,如果我按下静音按钮和动画循环,它总是回到音量= 1.如何循环而不总是回到音量= 1?

var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("Lyd/jetpass.mp3");
var channel1:SoundChannel = new SoundChannel();
var volumeAdjust:SoundTransform = new SoundTransform();
mute1.addEventListener(MouseEvent.CLICK, muteLyd);
volumeAdjust.volume = 1;
mySound.load(songURL);
channel1.soundTransform = volumeAdjust;
channel1 = mySound.play();

function muteLyd(e:MouseEvent):void {
    if(volumeAdjust.volume == 1){
    volumeAdjust.volume = 0;
} 
else {
  volumeAdjust.volume = 1;
}
channel1.soundTransform = volumeAdjust;
}

1 个答案:

答案 0 :(得分:0)

刚刚发现此代码解决了这个问题:

var mySound:Sound = new Sound();
var songURL:URLRequest = new URLRequest("Lyd/jetpass.mp3");
var channel1:SoundChannel = new SoundChannel();
mute1.addEventListener(MouseEvent.CLICK, muteLyd);
unmute1.addEventListener(MouseEvent.CLICK, unMuteLyd);

mySound.load(songURL);
channel1 = mySound.play();

function muteLyd(evt:MouseEvent){
    SoundMixer.soundTransform = new SoundTransform(0);
    unmute1.visible = true;
    mute1.visible = false;
}

function unMuteLyd (evt:MouseEvent){
    SoundMixer.soundTransform = new SoundTransform(1);
    unmute1.visible = false;
    mute1.visible = true;
}