Fade out music after playing for a minute AS3
I have a simple game I'm making and in it I want music to play for a minute and then fade out and then go to another frame. Here is the relevant code:
var songReq:URLRequest = new URLRequest("name.mp3");
var song:Sound = new Sound();
song.load(songReq);
var thesong:SoundChannel = new SoundChannel();
function startGameTimer():void {
trace("GAME TIMER STARTED");
var gameTimer:Timer = new Timer(60000, 1);//1min
gameTimer.addEventListener(TimerEvent.TIMER_COMPLETE, endGame);
gameTimer.start();
}
function endGame(e:TimerEvent){
trace("GAME TIMER ENDED");
thesong.stop();///want this to fade instead
var endTimer:Timer = new Timer(4000, 1);//fade out before transition
endTimer.addEventListener(TimerEvent.TIMER_COMPLETE,changeFrames);
endTimer.start();
}
function changeFrames(e:TimerEvent){
gotoAndStop(5);
}
what do I add/change to make the music fade out instead of suddenly stopping? I've been told I do something with tween but I don't know how that works if someone can help me out. Thank you
