stopping a sound file, Please help!!!!
Hi i have a program that allows me to press a key and it plays a sound here is the code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void
{
if (e.keyCode == 65 ) // A
{
var MySound:Sound = new Soundfile();
MySound.play();
}
}
This works fine but if i press the a key again before the sound has finished i want it to stop the sound and start it again. I thought i could do it like this:
function myKeyDown(e:KeyboardEvent):void
{
if (e.keyCode == 65 ) // A
{
var MySound:Sound = new Soundfile();
MySound.stop();
MySound.play();
}
}
by stopping the sound before i start it that way if it is playing and the key is hit it will stop and start again, i get this error though:
Error #1006: stop is not a function.
please please can someone help with this. oh iam using cs4 as3