2 Replies Latest reply on Sep 19, 2009 4:13 AM by Harm Meijer

    keyUp not called if application has non focasable components (example code)

    Harm Meijer

      It seems that keyUp event set on the application is not being called when there is no focasable element (like a button). In the example code keyUp is never called unless you set the focus on the button. Mousemove will hide/show the button, as long as you don't click on the button keyUp is never called.

      I need to capture keyUp captured for a list of questions (y or n) but my app has only labels so it never gets called, thinking of putting a dummy button on with 0 alpha and set the focus in init but wandering if there is a better way of doing this.

       

      Here is the code:

       

      <?xml version="1.0" encoding="utf-8"?>
         <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
         keyUp ="upKey(event);"
         mouseMove="moveMouse(event);"
         creationComplete="init();"
         width="900" height="325">
         <mx:Script>
         <![CDATA[
          import flash.events.Event;
          import flash.events.KeyboardEvent;
          import mx.controls.Alert;
              public function init():void {
                  // uncommenting the next line should fix it (work around)
                  // invisibleDummyButton.setFocus();
              }
             public function upKey(e:KeyboardEvent):void {
                 Alert.show("keyup, keycode: " + e.keyCode);
             }
             public function moveMouse(e:flash.events.Event):void{
                 Alert.show("Mouse move");
                 myButton.visible = !myButton.visible;
             }
         ]]>
         </mx:Script>
          <mx:Label x="10" y="50" text="Keyup does not work unless you set focus on the button" fontWeight="bold" fontSize="22"/>
          <mx:Button id="myButton" label="focus this and keyup works" visible="false"></mx:Button>
          <mx:Button id="invisibleDummyButton" alpha="0" label=""></mx:Button>
         </mx:Application>