currently i have a game in which i am try to play a sound when ever the player presses the arrow key to moves the car which is handled by an enter-frame function, but what ends up happening is that the sound is started again over and over and playing over each other as long as the key is held down eventually crashing the game. Below is the code i am using to play/stop the sound as well as the code for the enter-frame function (animate).
function sounds(): void
{
if (forwardPressed == true)
{
carMoveSound.play(pausePos);
trace('play sound');
return;
}
if (forwardPressed == false)
{
SoundMixer.stopAll();
trace('stop sound');
return;
}
}
function animate(e: Event)
{
moveCar();
checkHitBoundry();
checkHitObstacle();
checkLapFinish();
sounds();
if (gameOver)
{
endGame();
return;
}
}
Any help would be greatly appreciated.