# Sound fading with setinterval

**URL:** <https://forum.kirupa.com/t/sound-fading-with-setinterval/12692>\
**Category:** Uncategorized\
**Created:** [February 3, 2003, 4:44pm UTC](https://forum.kirupa.com/t/sound-fading-with-setinterval/12692 "2003-02-03T16:44:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stanley](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Stanley](https://forum.kirupa.com/u/Stanley)\
**Post date:** [February 3, 2003, 4:44pm UTC](https://forum.kirupa.com/t/sound-fading-with-setinterval/12692/1 "2003-02-03T16:44:17Z")

</div>

HELP ! i’m in trouble.

I am making a 3-song jukebox for a CD-rom. I’ve got a button for each song. And I’ve got 3 soundobjects. song1, song2, song3

when I press button 1:  
on(release){  
fadeout();  
\_root.newchoice = 1;  
song1.loadSound(“mp3/song1.mp3”,true);  
song1.play();  
}

// THIS FUNCTION SHOULD FADE OUT WHATEVER’s PLAYING (and start fading in the new song, but I haven’t even started thinking about that one… : ) )

function fadeout(){  
i=1;  
song=“song”+\_root.currentsong;  
var fadeintervalID;  
fadeintervalID = setInterval( lower\_volume, 50 );  
function lower\_volume(){  
if (i\<=100 && i\>=0){  
if (song == “song1”){  
song1.setVolume(100-i);  
}  
if (song == “song2”){  
song2.setVolume(100-i);  
}  
if (song == “song3”){  
song3.setVolume(100-i);  
}  
trace (\_root.currentsong);  
i+=1;  
}else{  
clearInterval(fadeintervalID);  
\_root.currentsong = \_root.newchoice;  
trace (\_root.currentsong);  
}  
}  
}

SO the problem is: I have to wait until the song has completely faded before I select the next one to get the result I want…(at the end of the fade the \_root.newchoice becomes the \_root.currentsong)

so for the moment I can hear all three songs with no fading if I press them one after the other fast enough…

get the problem ?  
Hins / solutions would be very much appreciated !

stanley :-\
