# \[Flex AS3\] Keyboard Events

**URL:** https://forum.kirupa.com/t/flex-as3-keyboard-events/223956
**Category:** flash
**Created:** [April 27, 2007, 3:44am UTC](https://forum.kirupa.com/t/flex-as3-keyboard-events/223956 "2007-04-27T03:44:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![saveth](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@saveth](https://forum.kirupa.com/u/saveth)
#### Post date: [April 27, 2007, 3:44am UTC](https://forum.kirupa.com/t/flex-as3-keyboard-events/223956/1 "2007-04-27T03:44:45Z")

</div>

I’ve been reading through Oreilly’s Actionscript 3.0 Cookbook and they had this example in there. As far as I can tell this does not work. If I remove the stage.focus = this; and change the addEventListener to be stage.addEventListener all is well. Is this a problem with there book or a problem with as3? Even alot of the examples in the Flex 2 help don’t work regarding this functionality.

```auto

package {
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    
    public class ExampleApplication extends Sprite {
        public function ExampleApplication( ) {
            stage.focus = this;
            addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        }
        
        private function onKeyDown(event:KeyboardEvent):void {
            trace("key down: " + event.charCode);
        }
    }
}

```
