Sorry to resurrect an old thread, but this is the one that came up in my google search, so I thought it'd be good to post a solution so anyone else who's trying to find the answer will have it.
Anyway, I came across this quick little trick that easily sets up an infinite loop without using any sort of 999 repeats (which can be problematic in long games or short loops, and just seems dangerous in general):
note that onSoundComplete does not guarantee a seemless loop.
I believe that starting with Flash 8 you could specifiy "infinite" loop in sound properties for sounds on the timeline, though this does not help the problem with infinite loop in sound object.
aviarts.com - web development and flash development
I just started flex a few days ago. I looked all over for a way how to loop background music. The only idea that I found worked was to put in the rediculously large # into the loop argument. Like so :
MySound.play(0, 999);
But I looked to the help files after still not satisfied~ In there I found SoundChannel. Used as so:
var channel : SoundChannel = MySound.play(0, 0);
You can catch the event when the song ends like so:
private function PlayAgain(event : Event) : void
{
channel.stop(); //<---- this I added just in case
channel.removeEventListener(Event.SOUND_COMPLETE, PlayAgain);
channel = MySound.play(0, 0);
channel.addEventListener(Event.SOUND_COMPLETE, PlayAgain);
}
I had to declare the sound and the channel as members of the class for this to work due to scope and the inability to assign anything to the event.target. For some reason the sound will not loop if you just set the channel equal to the sound. It will play a second time but thats it! So I added another event listener to try an make it play again. Now I wasn't sure if the event listeners, if already set, stack in AS3. So as to not have thousands of the same event listener on this one channel I remove it just before reassigning the sound to the channel. I looped sounds past 6 times so i'm going to say this works well. I hope this helps.
I read from the AS3 Cookbook and the author said there is no way to make sound loop forever but there is a way to make sound plays for a very long time by using
man that stinks so what i did was i made it start inside a movieclip and in the movieclip is 2 frames first one makes it start second stops it and when you press quit make it go to nextFrame(); for movieclip before it goes to another frame
I read from the AS3 Cookbook and the author said there is no way to make sound loop forever but there is a way to make sound plays for a very long time by using
Code:
this.play(0, int.MAX_VALUE);
The sound will play for approximately 70 years!
thank you so much man, this code was EXACTLY what i was looking for! quick simple and easy way to loop some BG music or anything of the like, thanks again!