My goal is to have a thruster sound when the player pushes the thrust button(up key) and stopwhen the key is released.
Currently it does sound when the thrust button is pushed but then won’t stop when it’s released.
Here’s my code:
var thrust:Sound = new thrusteri();
var pausePosition:Number = 0;
var thrustChannel:SoundChannel = new SoundChannel();
// later in an frame update function
if (_model.thrustOn == true)
{
thrustChannel = thrust.play(pausePosition);
// ..........then some code bringing in the thrust graphic and then
}
if (_model.thrustOn == false && thrustChannel!=null)
{
thrustChannel.stop();
pausePosition = thrustChannel.position;
}
UPDATE:
So whats happening is that if the player is holding down the thrust button(as the player does) a new layer of the thruster sound is started. How can I check to see if a sound is already playing? Maybe :
if( thrustOn==true && thrustChannel==null)
{
thrustChannel=thrust.play()
}
if(thrustOn== false && thrustChannel!=null)
{
thrustChannel.stop();
}