Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyUsed); // or use KEY_UP
function keyUsed(event:KeyboardEvent)
{
nextFrame(); // or prevFrame();
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now