User Guide
282 ActionScript classes
Example
In the following example, a function that sends text to the Output panel is defined for the
onKeyDown handler. Create a button called my_btn on the Stage, and enter the following
ActionScript in a frame on the Timeline:
my_btn.onKeyDown = function() {
trace("onKeyDown: "+this._name+" (Key: "+getKeyPressed()+")");
};
my_btn.onKeyUp = function() {
trace("onKeyUp: "+this._name+" (Key: "+getKeyPressed()+")");
};
function getKeyPressed():String {
var theKey:String;
switch (Key.getAscii()) {
case Key.BACKSPACE :
theKey = "BACKSPACE";
break;
case Key.SPACE :
theKey = "SPACE";
break;
default :
theKey = chr(Key.getAscii());
}
return theKey;
}
Press Control+Enter to test the SWF file. Make sure you select Control > Disable Keyboard
Shortcuts in the test environment. Then press the Tab key until the button has focus (a yellow
rectangle appears around the
my_btn instance) and start pressing keys on your keyboard.
When you press keys, they are displayed in the Output panel.
See also
onKeyDown (Button.onKeyDown handler), getAscii (Key.getAscii method), getCode
(Key.getCode method)
onKillFocus (Button.onKillFocus handler)
onKillFocus = function(newFocus:Object) {}
Invoked when a button loses keyboard focus. The onKillFocus handler receives one
parameter,
newFocus, which is an object representing the new object receiving the focus. If no
object receives the focus,
newFocus contains the value null.
Availability: ActionScript 1.0; Flash Lite 2.0