开发者

Play sounds in sequence when each has ended

开发者 https://www.devze.com 2022-12-15 19:58 出处:网络
I have 3 sounds that I would like to play, they are in my library. I can play any of of them using soundName.start(0,1) with开发者_StackOverflow社区 the code below:

I have 3 sounds that I would like to play, they are in my library.

I can play any of of them using soundName.start(0,1) with开发者_StackOverflow社区 the code below:

firstSound = new Sound();
firstSound.attachSound("Sound1");
secondSound = new Sound();
secondSound.attachSound("Sound2");
thirdSound = new Sound();
thirdSound.attachSound("Sound3");

The trouble i am having is, how can i know when sound1 has finished playing so i can then play sound2 and then sound3 immediately after?


You can calculate frame number of the sound ending using the framerate and sound lenght. After that you can call AddFrameScript(frameNum, function) and add code to play next sound.


In fact there exists a way in AS2, using onSoundComplete:

soundFX = new Sound();
soundFX.loadSound("sound.wav", true);
//or, if your sound is already in the library, 
//use soundFX.attachSound("librarySoundInstanceName");
soundFX.onSoundComplete = function() 
 {
//DO some action
/////////////
gotoAndStop("new12");
die();
newLevel();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消