Hi,
I have this problem when I try to fade in sound with the function below. It just doesn’t work and I can’t figure out where the problem is.
I would like to fade in a looping sound but nothing happens. I appreciate any hint I can get to solve this problem. Thanks in advance.
this is used to play a sound via events
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND, Main.SOUND_AMBIENT, false, true, false, 999999, 0, 0, setSoundVolume));
this is the function to play a sound. the stop-function is almost identical to this one.
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);
}
}
}
}