Posted By

mprabhuram on 07/14/09


Tagged

actionscript event Flex keypress


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

muoto
mprabhuram
tspitzr


KeyPress/keyboard events handling in Flex AS3


 / Published in: ActionScript 3
 

Use this code to handle keypress/keyboard events

  1. public function init():void
  2. {
  3. txtBox.addEventListener(KeyboardEvent.KEY_UP,pressEscape);
  4. }
  5.  
  6. public function pressEscape(event:KeyboardEvent):void
  7. {
  8. if (event.keyCode==13)
  9. {
  10. Alert.show("Enter Key has been pressed");
  11. }
  12. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: stealfish on January 19, 2011

this one differs the four keyboard keys, when added these you can add interactivity for example to program games etc... or use it as an intuitive website navigation..

import flash.events.KeyboardEvent; import flashx.textLayout.elements.BreakElement;

init(); function init():void { stage.addEventListener(KeyboardEvent.KEY_UP,pressEscape); }

function pressEscape(event:KeyboardEvent):void {

trace(event.keyCode);
if (event.keyCode == 13)
{
    trace("enter key has been pressed");
}
switch (event.keyCode)
{
        //up 38
    case 38 :
        br.y -=  30;
        break;
        //right 39
    case 39 :
        br.x +=  30;
        break;

        //down 40
    case 40 :
        br.y +=  30;
        break;

        //bottom 41
    case 41 :
        br.x -=  30;
        break;
}

}

You need to login to post a comment.