Events of the Key ObjectThe 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.
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. |