Link to home
Start Free TrialLog in
Avatar of ritetek
ritetek

asked on

Loading multiple songs with loadSound

I have a site that loads a song everytime a different page is loaded as follows,

var song:Sound = new Sound();
song.onLoad = function(success:Boolean):Void {
      if (success) {
            trace("Song Loaded");
      }
};
song.loadSound( "music/song1.mp3" , true);

I want to know if there is anyway to load a different song after the first one is finished playing, such as playing song1 until it finishes then playing song2.
ASKER CERTIFIED SOLUTION
Avatar of sam85281
sam85281

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ivan_os
ivan_os

Hi,

var songList = new Array("music/song1.mp3","music/song2.mp3","music/song3.mp3");
var songPlaying = 0;

var song:Sound = new Sound();
song.onSoundComplete = function ()
{
      songPlaying++;
      if(songPlaying == songList.length ) songPlaying = 0;
      _root.song.loadSound( songList[songPlaying] , true);
}

song.loadSound( songList[songPlaying] , true);

Regards,
ivan_os
Avatar of ritetek

ASKER

Thanks ivan, i'm sorry i couldn't give you points, but i will definitley use your method if i need to use a lot of songs.
No problem :o)
ivan_os