Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Location
    Schertz, TX
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    May 2006
    Location
    California
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •