Strike Force Heroes 2
The explosive sequel to the hit game Strike Force Heroes!
3.94 / 5.00 7,570 ViewsObsolescence
Defeat the enormous mechanical beasts--and become one of them.
4.01 / 5.00 40,158 ViewsIm very new to using audio in my flash projects, and quite frankly I'm finding it dreadful!
My biggest problem right now is that I need my song to loop repeatedly... I got this code set up so far, which seems like it should work... And it sort of does... but only once, the song plays twice on repeat, then stops. How can I get it to keep going?
var track1:Sound = new mainTheme();
var channel1:SoundChannel = new SoundChannel();
channel1 = track1.play();
channel1.addEventListener(Event.SOUND_COMPLETE, loopTrack1);
function loopTrack1(e:Event):void{
channel1 = track1.play();
}
Thanks!
Eh.
soundControl = sound.play(0, int.MAX_VALUE);
I know it's lazy, but there's a point where things aren't worth bothering with.
Actually, put the sound on the specified frame & on the bottom are actions. If you click on the frame that has the sound on it. On the bottom shows a variety of options. Go to the box saying repeat & click it, there will be a loop command. Once you do that, put a stop command, test your movie & hey! Presto!!!
If it doesn't make sense. I'll explain again.
At 5/22/12 03:30 AM, Krazzygamer3y2 wrote: Actually, put the sound on the specified frame & on the bottom are actions. If you click on the frame that has the sound on it. On the bottom shows a variety of options. Go to the box saying repeat & click it, there will be a loop command. Once you do that, put a stop command, test your movie & hey! Presto!!!
If it doesn't make sense. I'll explain again.
But then you can't start and stop the sound exactly when you need to, hence he's using code.
I decided to give this a go, and as with you, my track was only looping once. Firstly from the initial call of my function that played the track, and secondly because of the listener. Removing and re-hooking the event listener did the trick.
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.events.Event;
var channel:SoundChannel = new SoundChannel();
var track:Sound = new myLoop();
playTrack();
function playTrack(e:Event = null):void
{
if(channel.hasEventListener(Event.SOUND_COMPLETE))
channel.removeEventListener(Event.SOUND_COMPLETE, playTrack);
channel = track.play();
channel.addEventListener(Event.SOUND_COMPLETE, playTrack, false, 0, true);
}
Alternatively, if you don't need it looping indefinitely, you can also do:
import flash.media.SoundChannel;
import flash.media.Sound;
import flash.events.Event;
var channel:SoundChannel = new SoundChannel();
var track:Sound = new myLoop();
channel = track.play(0, int.MAX_VALUE);
This will loop the track 2147483647 times, which, practically is indefinite. This is a cleaner and my preferred way of doing it, but either works fine.
Yes, I did end up using max value to get it to loop, as it does seem a lot simpler than pointlessly trying to get it to really loop infinitely!
Thanks to everyone for the help!