I have a script using setInterval to audio clips in and out. fadeIn works right but fadeOut isn’t. Am I missing something? A typo?
bells = new Sound ();
bells.attachSound ("bells");
cricket = new Sound ();
cricket.attachSound ("cricket");
birds = new Sound ();
birds.attachSound ("birds");
var sound_iv:Number;
var sound_ov:Number;
function fadeIn (soundClip):Void {
soundClip.start ();
soundClip.setVolume (0);
sound_iv = setInterval (function () {
if (_vol == undefined) {
_vol = 0;
}
_vol++;
soundClip.setVolume (_vol);
if (_vol == 100) {
trace ("FadeIn done");
clearInterval (sound_iv);
}
}, 10);
}
function fadeOut (soundClip):Void {
soundClip.setVolume (100);
sound_ov = setInterval (function () {
if (_vol == undefined) {
_vol = 100;
}
_vol--;
soundClip.setVolume (_vol);
if (_vol == 0) {
trace ("FadeOut done");
clearInterval (sound_ov);
}
}, 10);
}
fadeIn(birds);