0
[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;
}
}
我'嘗試循環的嵌入式音樂,但只有第一個隨機歌曲播放,然後是隻有沉默......不明白爲什麼下一首歌曲沒有按不玩,誰能告訴我?不能循環內嵌聲音柔性
我已經改變了這一點,但第一首歌后,仍是未來不打......想不通爲什麼 –
你查看控制檯中的任何錯誤?嘗試在歌曲完整處理程序中添加跟蹤語句或斷點,以確保正在執行。 –
其實,看到更新的答案。你的條件允許索引超出你的數組的範圍,並且你正在測試音樂。長度而不是music.length,它會在執行時立即拋出錯誤。 –