Copy link to clipboard
Copied
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!
You renamed the event handler function such that the event listener is specifying/calling a function that doesn't exist
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
You renamed the event handler function such that the event listener is specifying/calling a function that doesn't exist
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now