Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Registering a command to a key

New Here ,
Feb 01, 2013 Feb 01, 2013

I want to add a command to a key and I want to know how to do this. For example, if the user presses any key, they will move back one frame or forward a frame. Can anyone tell me the Actionscript for this? Thanks

TOPICS
ActionScript
351
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 01, 2013 Feb 01, 2013

You will need to add an event listener first:

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

and then define the function

function keyDownHandler(e:KeyboardEvent):void

{

     switch(e.keyCode)

     {

          case Keyboard.W:

               // do something

               break;

     }

}

That would define a command to the W key. The Keyboard class has many constants for keys.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2013 Feb 01, 2013
LATEST

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyUsed);  // or use KEY_UP

function keyUsed(event:KeyboardEvent)
{

         nextFrame();  // or prevFrame();
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines