Disabling repeating keyboard down event in as3
Posted
by psy-sci
on Stack Overflow
See other posts from Stack Overflow
or by psy-sci
Published on 2010-04-30T20:53:03Z
Indexed on
2010/04/30
20:57 UTC
Read the original article
Hit count: 234
now I'm trying to make the keyboard events to stop repeating.
My idea was to have a true and false condition for when the key is pressed so that it wont repeat if the key is down already.
//Mouse Event Over
keyCButton.addEventListener(MouseEvent.MOUSE_OVER, function(){gotoAndStop(2)});
//Variable
var Qkey:uint = 81;
//Key Down Event
stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown);
var soundplayed = false;
function keydown(event:KeyboardEvent){
if (event.keyCode==Qkey) {
this.soundplayed=true;}
}
if (this.soundplayed==false){
gotoAndPlay(3);
} else {}
//Key Up Event
stage.addEventListener(KeyboardEvent.KEY_UP, keyup);
function keyup(event:KeyboardEvent){
if (event.keyCode==Qkey) {
this.soundplayed=true;
gotoAndStop(1);
}
}
doing this just turns off the key event I think i need to add a "&& keyDown..." to "if (this.soundplayed==true)" but i dont know how to do it without getting errors
here is the keyboard player i'm trying to fix http://soulseekrecords.org/psysci/animation/piano.html
© Stack Overflow or respective owner