You can add the listener to the stage object:

stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown_handler); 

Or you can set the focus on the app in init():

        application.addEventListener(KeyboardEvent.KEY_DOWN,
keydown_handler); 
        application.setFocus();

Hth,

Matt Horn
Flex docs

> -----Original Message-----
> From: flexcoders@yahoogroups.com 
> [mailto:[EMAIL PROTECTED] On Behalf Of bhaq1972
> Sent: Friday, June 09, 2006 10:26 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] flex2b3 - keydown re-visted
> 
> Hi,
> 
> i had this problem in flex2b2 but now have decided to tackle 
> this again in b3.
> 
> In this example (see below),
> 1) set focus on the label (using your mouse), and then hit 
> your keyboard...nothing happens
> 2) now try again but this time set focus on the button (using 
> mouse) and then hit your keyboard......this time you trap 
> keyboard events.
> 
> The problem is keyDown events are not trapped unless you have 
> selectable gui (ie anything which can have a tabIndex eg Button,
> TextInput) ......which you can first focus on with your mouse.
> 
> if your component/application has non selectable gui (eg 
> Labels, other containers), then no matter how many times you 
> click/mouseDown on thes object......you will never trigger 
> keydown events.
> 
> In flex 1.5 i had this problem but was able to solve it by using
> Key.addListener() function.
> 
> All i want to do is be able trap keydown events, where ever 
> my mouse focuses on.
> 
> code
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml 
> <http://www.adobe.com/2006/mxml> " 
> creationComplete="init()">
> 
> <mx:Script>
> <![CDATA[
> 
> import flash.events.KeyboardEvent;
> import mx.controls.Alert;
> 
> private function init():void
> {
> this.addEventListener
> (KeyboardEvent.KEY_DOWN, keydown_handler); }
> 
> private function keydown_handler(e:KeyboardEvent):void
> {
> Alert.show("trapKeys()");
> }
> 
> ]]>
> </mx:Script> 
> 
> <mx:Box id="box1" width="100%" height="100%" 
> backgroundColor="red">
> <mx:Label text="test" />
> <mx:Button label="test" />
> </mx:Box> 
> 
> </mx:Application>
> 
> 
> 
>  
> 


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Home is just a click away.  Make Yahoo! your home page now.
http://us.click.yahoo.com/DHchtC/3FxNAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to