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. :cap:
Printable View
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. :cap:
El bump.
Bump.
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?PHP Code:stop();
yeah, if you only want that event to happen on the one frame, add this to the switch statement under "case 76:"
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).PHP Code:stage.removeEventListener(KeyboardEvent.KEY_DOWN,onKeyboardDown);
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.
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).