CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Adobe Flex (http://www.codingforums.com/forumdisplay.php?f=63)
-   -   How to read keyboard input? (http://www.codingforums.com/showthread.php?t=146056)

Chantcd_com 08-06-2008 10:54 PM

How to read keyboard input?
 
(I just found this sub-forum...sorry about posting it in the main Flash/Actionscript forum...)

My program starts out this way:


Code:

    public class MyProgram extends UIComponent
{

...

Now I heard that any UIComponent registers keyDownHandler automatically, so you just need to override that function.

But although I get no errors, there is NO sign of life as far as keyboard input goes. I programmed the keys to do some drastic things (not shown below) but nothing ever happened. So I'm wondering what I'm doing wrong.

Code:

                override protected function keyDownHandler(e:KeyboardEvent):void {
                        if (e.keyCode == Keyboard.LEFT) {
                              trace("LEFT");
                        }
                        if (e.keyCode == Keyboard.UP) {
                              trace("UP");
                        }
                        if (e.keyCode == Keyboard.DOWN) {
                              trace("DOWN");
                        }
                        if (e.keyCode == Keyboard.RIGHT) {
                              trace("RIGHT");
                        }
                       
                }

Any help would be much appreciated.

Thanks,

Matthew

Forsaken 08-08-2008 05:10 PM

I'm not 100% sure but I've had the same problem, by default I think what the problem is unless you've used your mouse to click on that object that object won't detect the keyboard events. I noticed this when I first used a tilelist, then I noticed this when using a circle shape in AS3.


All times are GMT +1. The time now is 06:18 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.