Friday, November 7, 2008

Flex 3 - KeyBoard Events, Flash Player 10 vs Flash Player 9

In trying to work on one of the requirements which requires us to handle Shortcut keys (example: Cntrl+1, Cntrl+2 etc), Using Flex Keyboard events, I happened to hit upon this same on the live docs. Flex 3 Docs Sample

Initially i thought It broken in Flash player 10 and is working fine in flash player 9. Place your cursor in the Text area below and press (cntrl+1) and see what you get. (Keycode for Cntrl key = 17). This swf is generated using flash player 10

See this SWF (generated using flash player 9) which works almost the same way. Place your cursor in the Text area below and press (cntrl+1) and see what you get. If you press the keys 'cntrl' and '1' fast and release them fast, only cntrl event is fired and cntrl+1 event is not fired. Keep doing it fast, and at one point you will see both the keys start to respond, from here on everything keeps to be working. Open the url in a new browser window to retry this scenario (looks like key-up event is not getting fired initially when we press and release the keys faster).

And here the the same code that made it happen..

        private function initApp():void {
            application.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
            my_vbox.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
            my_textinput.addEventListener(KeyboardEvent.KEY_UP, keyHandler);

            // Set the focus somewhere inside the application.
            my_textinput.setFocus();
        }

        private function keyHandler(event:KeyboardEvent):void {
            ta1.text += event.target + "(" + event.currentTarget + "): " + 
                event.keyCode + "/" + event.charCode + "\n";
        }




    
        
    

    



0 comments: