要在 AS3 中更改声音的音量,您需要使用SoundChannel
和SoundTransform
类:
var backgroundMusic:Sound = // Assuming you've loaded a sound
var myChannel:SoundChannel = new SoundChannel();
myChannel = backgroundMusic.play();
var myTransform = new SoundTransform();
myChannel.soundTransform = myTransform;
通过在调用期间增加计数并在事件期间play
减少计数来跟踪背景中的总声音。SOUND_COMPLETE
将事件侦听器添加到其他声音的通道,以便他们可以修改background
的音量:
var totalCurrentSounds:int = 0;
otherSoundChannel.addEventListener(Event.SOUND_COMPLETE, otherSoundComplete);
// Make sure this is on a SoundChannel, not the Sound itself.
最后,在count为0时修改SoundTransform
'成员:volume
function otherSoundComplete(e:Event):void {
totalCurrentSounds--;
if (totalCurrentSounds <= 0)
myTransform.volume = 0.5;
}