...

View Full Version : How to read keyboard input?



Chantcd_com
08-06-2008, 10:54 PM
(I just found this sub-forum...sorry about posting it in the main Flash/Actionscript forum...)

My program starts out this way:



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.


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum