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

    Handling Keyboard Events

    Shirker1

      Hi:

      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"?>

      <mx:WindowedApplication

      xmlns:mx="http://www.adobe.com/2006/mxml"

      layout="

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

      </mx:ApplicationControlBar>

      <mx:Array

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

      <mx:Script>

      <![CDATA[
      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")};

      ]]>

      </mx:Script>

      </mx:WindowedApplication>

       

       

       


        • 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.

           

          Jason