package {
import flash.display.Sprite;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;
import flash.media.SoundChannel;
public class Main extends Sprite {
private var _sound:Sound;
private var _channel:SoundChannel;
private var _playList:Array; // the list of songs
private var _index:int = 0; // the current song
public function Main() {
_playList = ["song1.mp3",
"song2.mp3",
"song3.mp3"];
playNextSong( );
}
private function playNextSong( ):void
{
if(_index < _playList.length) {
_sound = new Sound( );
_sound.load(new URLRequest(_playList[_index]));
_channel = _sound.play( );
_channel.addEventListener(Event.SOUND_COMPLETE,onComplete);
_index++;
}
}
public function onComplete(event:Event):void
{
playNextSong( );
}
}
}
|