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

Key based timeline navigation in action script 3

Community Beginner ,
Jul 11, 2014 Jul 11, 2014

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!

TOPICS
ActionScript
421
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

correct answers 1 Correct answer

LEGEND , Jul 12, 2014 Jul 12, 2014

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

Translate
LEGEND ,
Jul 12, 2014 Jul 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.

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
Community Beginner ,
Jul 12, 2014 Jul 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!

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 ,
Jul 12, 2014 Jul 12, 2014

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

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
Community Beginner ,
Jul 12, 2014 Jul 12, 2014
LATEST

AHA!!!

stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);

function myKeyDown(e:KeyboardEvent):void{

if (e.keyCode == Keyboard.SPACE){

    gotoAndPlay(1);

}

}

Good yes!

Thank you so much for the help!

It means a lot.

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