Skip to main content
Antired1
Participant
July 12, 2014
Answered

Key based timeline navigation in action script 3

  • July 12, 2014
  • 1 reply
  • 481 views

Hello!

I have been using action script 2 for a bit and have gotten decent with it. I am currently doing a project that requires a lot of key based navigation of the timeline. But I can't seem to figure it out in action script 3?

In action script 2 I could just type something like...(Bad example)....On key press "A" Gotoandplay (5)

But as I said I can't figure things out in action script 3. I have learned how to use an on screen button to do this but that is not the aim of the project.

Any help would be very appreciated!

Thanks in advanced!

This topic has been closed for replies.
Correct answer Ned Murphy

You renamed the event handler function such that the event listener is specifying/calling a function that doesn't exist

1 reply

Ned Murphy
Legend
July 12, 2014

In AS3 just about anything involving interaction requires the use of event listeners.  For keyboard events it is no different.  Here is a basic example:


function hearKeyDown(evt:KeyboardEvent):void{   
    trace(evt.keyCode, "keydown");
}

function hearKeyUp(evt:KeyboardEvent):void{    

    trace(evt.keyCode, "keyup");
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKeyDown);

stage.addEventListener(KeyboardEvent.KEY_UP, hearKeyUp);

To build upon that example you can take the value of the evt.keyCode and use it to determine which key was used and what action to take as a result.

Antired1
Antired1Author
Participant
July 12, 2014

Fantastic!

Let me just make sure I have this right.

stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKeyDown);

function fl_KeyboardDownHandler(event:KeyboardEvent):void  

    trace(evt.keyCode, "KEY_DOWN")

    gotoAndPlay(5); }

Hmmm I'm getting an error?

Pray patience! I am rusty!

Ned Murphy
Ned MurphyCorrect answer
Legend
July 12, 2014

You renamed the event handler function such that the event listener is specifying/calling a function that doesn't exist