Copy link to clipboard
Copied
Hello,
I am currently making a presentation where I need to use the left and right arrow keys to navigate movie clips. Everything seems to be working fine with the exception of the left arrow key. Here is my code.
This code is on frame 35 inside a movie clip. This movie clip is on Scene1, frame 3. The left key (37) will take the user back to Scene1, frame 2. The right key (39) will take the user to frame 36 on this movie clip.
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);
function fl_KeyboardDownHandler(event:KeyboardEvent){
if (event.keyCode == 37){
MovieClip(parent).gotoAndStop(2);
}
else if (event.keyCode == 39){
gotoAndPlay(36);
}
}
This seems to work fine. However, when I have another action further down the timeline of this movie clip, the left key still wants to go to Scene 1, frame 2 and not to a frame within the movie clip. Here on frame 55 in the movie clip, the left key should take the user to frame 35 and the right key to frame 56. The right key works but the left key does not.
stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler2);
function fl_KeyboardDownHandler2(event:KeyboardEvent){
if (event.keyCode == 37){
gotoAndStop(35);
}
else if (event.keyCode == 39){
gotoAndPlay(56);
}
}
Any help would be greatly appreciated. Also, if you need more information please let me know.
Thanks,
Shannon
yes, you need to do that:
stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);
Copy link to clipboard
Copied
did you remove the previous listener?
Copy link to clipboard
Copied
No, I didn't remove it. Is there code to remove a previously added listener before adding another? And again why would it work for the right arrow and not the left arrow?
Copy link to clipboard
Copied
yes, you need to do that:
stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);
Copy link to clipboard
Copied
Thank you! That worked great! I didn't realize there was a remove function. I grately appreciate your time in answering this for me.
Copy link to clipboard
Copied
you're welcome.