Events of the Key Object

Events of the Key Object

The keyboard is the most important way users interact with applications. It is the only way to enter pertinent information into forms. The Key object is the object that captures events associated with keyboard interaction.

Table 14.4 shows the events for the Key object.

Table 14.4. Key Events

Event Handler Methods

Action Description


This event occurs when the user presses a key on the keyboard.


This event occurs when the user releases the key that has been pressed.

Now that you've seen the two events associated with the Key object, here is a code example using the onKeyDown event:

 //create the object to listen to the Key var keyListen:Object = new Object(); //create the event keyListen.onKeyDown = function(){    //trace the character you pressed    trace(String.fromCharCode(Key.getAscii())); } //add the listener Key.addListener(keyListen); 

The preceding code creates the listener object. Then it creates the event-handling method that includes the trace function that will send the character the user presses to the Output panel using the String object with the Key object.

Run the code, and if nothing happens at first, give the focus to the stage by clicking on it once. Then, when you use the keyboard, you should begin to see letters appearing in the Output panel.

Another object that uses events is the TextField object.

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319 © 2008-2017.
If you may any questions please contact us: