user1454751
user1454751

Reputation: 1

loop sound actionscript Flash

i want to know if anyone can help me with actionscript in Flash.

i want to have some different buttons and play different sound loops when i click in the button, but every loop has to start when the other finished because of the music melody. can anyone help me?

Thank you

Teresa

Upvotes: 0

Views: 142

Answers (2)

Allan Banis
Allan Banis

Reputation: 386

Well i am assuming you want to play the sound associated with the last button pressed and not play many sounds together.

So you have a global sound variable which you change on button press

var sound:Sound=new Sound(new URLRequest("music.mp3"));
var soundChannel:SoundChannel=new SoundChannel();
soundChannel=sound.play();
soundChannel.addEventListener(Event.SOUND_COMPLETE,loop_Sound);
function loop_Sound(e:Event){
      soundChannel=sound.play();
      //I know you don't need to add the listener again to the sound channel 
      //but this is something i just do
      soundChannel.addEventListener(Event.SOUND_COMPLETE,loop_Sound); 
}
//call this function when the button is pressed
//you could name the button name as the sound file's name 
//and use e.currenttarget.name or something
function change_Sound(e:MouseEvent){
   sound=new Sound(new URLRequest("music2.mp3"));

}

This would load the sound when the button is pressed but play it only when your current sound finishes playing and if the button is not pressed while it is playing it would loop the current sound .Best Of Luck!!

Upvotes: 0

Kritavarman
Kritavarman

Reputation: 28

By using SoundChannel class in AS3, you can get addEventListener - Event.SOUND_COMPLETE, which will notify you about the sound complete and then you can play the next sound

Upvotes: 1

Related Questions