2012-03-20 10 views
0

順に配列に聞こえます。最初の音が止まると、最後の音が鳴るまで、2番目の音が始まります。最後のサウンドが終了すると、すべてのサウンドが停止し、再生ボタンをもう一度押すと、最初からやり直してから、再びすべてのサウンドを再生する必要があります。AS3プレイこれはフラッシュCS5.5でプログラムされている

現在、次のサウンドに進むには、もう一度ボタンを押す必要があります。私はSOUND_COMPLETEを使用する必要があると思っています...私はちょうど、どのように空の関数がわからない。シーケンス全体を聞くために一度演奏しなければならないだけです。何か案は?

var count; 
var songList:Array = new Array("test1.mp3","test2.mp3","test3.mp3"); 

count = songList.length; 
myTI.text = count; 
var currentSongId:Number = 0; 

playBtn.addEventListener(MouseEvent.CLICK, playSound); 

function playSound(e:MouseEvent):void{ 
if(currentSongId < songList.length) 
{ 
var mySoundURL:URLRequest = new URLRequest(songList[currentSongId]);   
var mySound:Sound = new Sound(); 
mySound.load(mySoundURL); 
var mySoundChannel:SoundChannel = new SoundChannel(); 

mySoundChannel = mySound.play(); 
currentSongId++; 
mySoundChannel.addEventListener(Event.SOUND_COMPLETE,handleSoundComplete) 
} 
if(currentSongId == songList.length) 
{ 
    currentSongId = 0; 
} 
} 

function handleSoundComplete(event:Event){ 
} 

答えて

1

機能を調整してコードを読みやすくする必要があります。

private Array songList = new Array("test1.mp3", "test2.mp3"); 




public function onPlayBtnPressed(){ 
    currentSongIndex = 0; 
    PlaySongFromIndex(currentSongIndex); 
} 


public function PlaySongFromIndex(songIndex:int){ 
    //do what ever here to simply play a song. 
    var song:Sound = new Sound(songList[songIndex]).Play() 
    //Addevent listener so you know when the song is complete 
    song.addEventListener(Event.Complete, songFinished); 
    currentSongIndex++; 
} 

public function songFinished(e:Event){ 
    //check if all the songs where played, if so resets the song index back to the start. 
    if(currentSongIndex < listSong.Length){ 
     PlaySongFromIndex(currentSongIndex); 
    } else { 
     currentSongIndex=0; 
    } 
} 

これはちょうどexempleを示すためにコンパイルされていません。

+0

ありがとう、これが私を助けました。私はあなたの提案ごとにそれを分解することでそれを理解することができました。乾杯! – user1129107

+0

うれしい私はどんな助けでもあった:) –

関連する問題