1 Reply Latest reply on Jan 14, 2010 11:47 AM by Jason Szeto

    Handling Keyboard Events

    Shirker1 Level 1


      Below is an Air application in which I am trying to catch keyboard events.

      I do catch it once. Subsequently when I try to catch the events, sometimes I must click on the canvas

      to refocus. Sometimes even this does not work. When I choose an option in DropDown list then the handler

      also stops working. Is there something missing in my envent Handler?

      Please advise and thanks for reading and helping.


      <?xml version="1.0" encoding="utf-8"?>




      absolute" windowComplete="windowComplete();"> <mx:ApplicationControlBar id="dockedBar" dock="true" paddingLeft="0" paddingRight="0"> <mx:ComboBox dataProvider="{stats}" id="statsC" change="statsChangeEvt(event)" />



      id="stats"> <mx:Object label="Option 1"/> <mx:Object label="Option 2"/></mx:Array>


      import mx.controls.Alert; private function windowComplete():void{stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);} public function handleKeyDown(event:KeyboardEvent) :void{Alert.show("Key pressed");} private function statsChangeEvt(event:Event):void { Alert.show("Stats Changed")};







        • 1. Re: Handling Keyboard Events
          Jason Szeto Level 3

          Try listening to the keyDown event in the capture phase.

          addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown, true).


          ComboBox stops the propogation of the event if it is something that it handles. This is why you don't get it in the bubble phase.