views:

127

answers:

1

Hi people,

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 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 immediatly after?

Thanks, Kohan.

+1  A: 

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.

alexm
That sounds rather complex, i wouldn't know where to begin with that. I take it there is no event for this kind of thing then? I tried firstSound.addEventListener("complete",myListener); var myListener = new Object(); myListener.complete = function() { trace("done"); };but this does not fire.
Kohan
this is how to get sound duration:var c_snd:Sound = new Sound();c_snd.attachSound("linked_sound");trace('duration: ' + ((c_snd.duration/1000)<<0) + 's');divide this by your frame rate, and you'll get the frame number where it ends.Let's call it "some_frame";use some_movie_clip.AddFrameScript(some_frame, your_sound_start_function).I assumed that you start 1st sound at frame 0, and in main movie clip.
alexm
Hi there, thanks for the code, i think AddFrameScript is AS3 but i might be able to get it working with some form of delay thanks to you.
Kohan
yes it's AS3 sorry, anyway glad it was useful for you
alexm