1 Reply Latest reply on Apr 21, 2013 5:14 AM by Ned Murphy

    Catching the KeyboardEvent

    flashas3 Level 1

      Hello, I  just created a login form. I have two input fields on stage. I want the user to fill their details in the input fields then press the enter key to login. I am just wondering what the best approach is. Do I use the keyboardevent or should I use a textinput to dispatch an enter event?  This is my code im not sure how this works.                                                                                                            inputOne.addEventListener(KeyboardEvent.KEY_DOWN,enterKey);  function enterKey(event:KeyboardEvent):void{ if(evnt.keyCode == Keyboard.ENTER) trace("we pressed enter");

        • 1. Re: Catching the KeyboardEvent
          Ned Murphy Adobe Community Professional & MVP

          You can add the listener to the stage, though assigning it to textfield might work equally well.

           

          If the code you show is not working it might be because you change the argument from "event" ti "evnt" inside the function.  Also, you might want to consider using the KEY_UP event instead of the KEY_DOWN since it is the end of the action of using the Enter key.

           

          In any case the approach you are taking is fine.  You can assign an Event.CHANGE listener to the textfield if you want to monitor the user inpout as it gets entered.