Skip to main content
Participating Frequently
October 15, 2007
Question

Music Looping

  • October 15, 2007
  • 4 replies
  • 363 views
I've added some background music to my site with a start/stop button. I'd really like the music to loop. I found another post on how to do this but the script isn't working for me... Here is what I have:

var amb:Sound = new Sound();
amb.loadSound("music/IntroAmb1.mp3", true);
amb.start(0, 1000);

play_btn.onPress = function() {
amb.stop();
amb.start(0, 1000);
}

stop_btn.onPress = function() {
amb.stop();
}

As I understand it, the sound object allows me to declare how many times my music loops with:

amb.start(secondsOffset, loops);

As you can see I've set the loop number to 1000, but it doesn't repeat. Can anyone tell me what's wrong? Thank you!!
This topic has been closed for replies.

4 replies

shojinateAuthor
Participating Frequently
October 15, 2007
Yes, thank you for the great help! I have another question;

What if I wanted to pause the audio instead of stopping it? Can this be done?
clbeech
Inspiring
October 15, 2007
sure, Flash can do anything!! (... almost, LOL)

You could 'store' a variable with the 'position' property at the time of 'pausing' then when using the start() method, use the var to offset the sound to the correct time. let's see ...

EDIT: Sorry, I was a little hasty with my answer here!!! LOL!! the corrected code has been entered below now!

clbeech
Inspiring
October 15, 2007
you're welcome :)
shojinateAuthor
Participating Frequently
October 15, 2007
It works wonderfully, thank you!
clbeech
Inspiring
October 15, 2007
yes, but the 'start()' method is only used for embedded sounds attached from the Library, you a 'streaming' in the music file, so use this instead:

amb.onSoundComplete = function() {
amb.start(0, 1000);
}

once the sound has been completely loaded you can then use the start() method. You could alternatively, load the sound first setting the 'stream' param to 'false' then use the amb.start(0, 1000) call, but it will wait until the sound is completely loaded to start playing it.