褪色的声音不起作用

时间:2012-01-09 22:11:38

标签: actionscript-3 audio

当我尝试使用下面的功能淡入声音时,我遇到了这个问题。它只是不起作用,我无法弄清问题在哪里。 我想淡出一个循环的声音,但没有任何反应。我很感激我可以解决这个问题的任何提示。提前谢谢。

这用于通过事件播放声音

dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND, Main.SOUND_AMBIENT, false, true, false, 999999, 0, 0, setSoundVolume));

这是播放声音的功能。停止功能几乎与此相同。

public function playSound(soundName:String, isSoundTrack:Boolean = false, fadeIn:Boolean = false, fadeOut:Boolean = false,
                              loops:int = 1, offset:Number = 0, volume:Number = 1):void {

        if (fadeIn) {
            tempSoundTransform.volume = 0;
        } else {
            tempSoundTransform.volume = volume;

        }
        tempSound = sounds[soundName];

        if (isSoundTrack) {
            if (soundTrackChannel != null) {
                soundTrackChannel.stop();
            }

            soundTrackChannel = tempSound.play(offset, loops);                              
            soundTrackChannel.soundTransform = tempSoundTransform;

            if (fadeIn) {
                for (var i:int = 0; i < fadeInInc; i++) {
                    tempSoundTransform.volume += 1 / fadeInInc;
                    soundTrackChannel.soundTransform = tempSoundTransform;  
                    if (tempSoundTransform.volume >= 1) {
                        tempSoundTransform.volume = 1;

                    }
                }
            }

        } else {
            soundChannels[soundName] = tempSound.play(offset, loops);
            soundChannels[soundName].soundTransform = tempSoundTransform;

            if (fadeIn) {
                for (var i:int = 0; i < fadeInInc; i++) {

                    tempSoundTransform.volume += 1/fadeInInc;
                    soundChannels[soundName].soundTransform = tempSoundTransform;   
                    if (tempSoundTransform.volume >= 1) {
                        tempSoundTransform.volume = 1;

                    }

                    trace("tempSoundTransform.volume " + tempSoundTransform.volume);
                }
            }

        }

    }

1 个答案:

答案 0 :(得分:3)

我认为您的问题是由“for”语句引起的。程序将等待for语句结束并在此之后设置值。如果你想平行增加音量值,你应该在ENTER_FRAME事件上做或尝试Sounds fade in/out with ActionScript 3