-
Press a key from the keyboard and move to next frame
Hi everyone,
How do you press a key (like "L") and go to the next frame?
Which event must I pick?
I assume it's something like: stage.addEventListener(Keyboard., but after that I don't know what to do.
This is for AS 3.0 by the way.
Thanks.
-
-
-
Bald By Choice
PHP Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyboardDown,false,0,true);
function onKeyboardDown(e:KeyboardEvent):void{ trace(e.keyCode); switch (e.keyCode){ case 76: nextFrame(); break; default: //do nothing return; } }
-
Thanks.
But it also affects all frames after the one where the code is. I just wanted to happen in one particular frame.
I'm placing the code on the timeline, and each of of the next frames only have:
Must I remove the eventListener?
-
Bald By Choice
yeah, if you only want that event to happen on the one frame, add this to the switch statement under "case 76:"
PHP Code:
stage.removeEventListener(KeyboardEvent.KEY_DOWN,onKeyboardDown);
And yeah, keep the stop actions at the top/bottom of your script (doesn't matter where it is as long as it's there).
-
Yah, that was what I did. But isn't there a way for the code to affect on that particular frame only?
It's not very code effective pasting the same line of code on all the other frames.
Thanks.
-
Bald By Choice
Not sure what you mean. It is only affecting that one frame since you kill the event listener after you're off that frame. You want to use that function on other frames too? Then just re-add the event listener on those frames (you won't need to re-define the method, so no copypasta and it should still work fine).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|