-
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
Last edited by Flashnoobee; 04-20-2010 at 01:34 PM.
Reason: missed out what version iam using
-
for external sound...
Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
var MySound:Sound;
var channel:SoundChannel;
function myKeyDown(e:KeyboardEvent):void {
if (e.keyCode==65) {
// 65 is a
if (! MySound) {
MySound = new Sound();
MySound.load(new URLRequest("song.mp3"));
} else {
channel.stop();
}
channel=MySound.play();
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|