循环AS3后的音量控制



我的代码有问题。该代码效果很好,有一个例外,如果我按了静音键和动画循环,它始终返回卷= 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;
}

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

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

最新更新