I am making a Flash game with a bird as the avatar. And when the bird picks up an Iron Bird pickup, the song Iron Man is played. But the problem is: It keeps making new instances of this audio. So I have like a hundred thousand Ozzy’s singing the song. But they have a delay of a second between each other. Is there a certain function to play the song only one time? Or a small script to get this done?
This is my script:
var IronManMusic:Sound = new IronManSong();
var IronManChannel:SoundChannel = new SoundChannel();
var backgroundMusic:Sound = new BackgroundMusic();
var myChannel:SoundChannel = new SoundChannel();
myChannel = backgroundMusic.play();
if(ironbird==true){
laatstejump = 9;
myChannel.stop();
IronManChannel = IronManMusic.play();
}
The ironbird boolean is found in a Updatescreen function. I think this is the problem but I am not sure. Help is really appreciated! 🙂
Hm… looks like it should be:
Or at least the Updatescreen function you mentioned should set
ironbirdback tofalseafter one tick/iteration.EDIT: Looking at the code you posted as an answer, it’s even easier:
You’re doing
and use the
ironbirdvariable for animation and other things. Moving the sound trigger should only trigger the sound once (or as often as hitTestPoint is triggered).You should still reset
ironbirdtofalsesomewhere, f.e. when animation is done.