To add to what IndieFlashArcade said, you must also add whatever the onKeyDown or onKeyUp event is being called from as a listener for the Key class. Using his example,
this.onKeyDown = function() {
if( allowable ) {
actions
}
allowable = false;
};
this.onKeyUp = function() {
allowable = true;
};
Key.addListener(this);
Additionally, if you want to check for a specific key, you can use the getCode() method of the Key class, which returns the key code of the key pressed as a number. Again, using his example, it would be something like…
this.onKeyDown = function() {
if( allowable && Key.getCode() == KEYCODE ) {
actions
}
allowable = false;
};
…where you replace KEYCODE with the key code of the desired key. Most key codes you would find yourself using are listed here.
|