[Embed('sounds/music1.mp3')]
public var Music1:Class;
[Embed('sounds/music2.mp3')]
public var Music2:Class;
[Embed('sounds/music3.mp3')]
public var Music3:Class;
public var music:Array;
public var currentSongIndex:int;
public function complete():void {
stage.scaleMode = StageScaleMode.SHOW_ALL;
stage.frameRate = 32;
music = new Array();
music.push(new Music1());
music.push(new Music2());
music.push(new Music3());
currentSongIndex = Math.floor( Math.random() * music.length );
var playFirst:SoundAsset = music[currentSongIndex] as SoundAsset;
playFirst.addEventListener(Event.COMPLETE, songFinished);
playFirst.play();
}
public function PlaySongFromIndex(songIndex:int){
var playFirst:SoundAsset = music[currentSongIndex] as SoundAsset;
playFirst.addEventListener(Event.COMPLETE, songFinished);
playFirst.play();
}
public function songFinished(e:Event){
if(currentSongIndex < music.Length){
currentSongIndex++;
PlaySongFromIndex(currentSongIndex);
} else {
currentSongIndex=0;
}
}
我正在尝试循环播放嵌入的音乐,但只播放第一首随机歌曲,然后只是静音......不明白为什么下一首歌曲不播放,谁能告诉我?