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

Navigating with Arrow Keys - AS3

Explorer ,
Sep 06, 2023 Sep 06, 2023

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

TOPICS
ActionScript , How to , Timeline

Views

144

Translate

Translate

Report

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

Community Expert , Sep 07, 2023 Sep 07, 2023

yes, you need to do that:

 

stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);

Votes

Translate

Translate
Community Expert ,
Sep 06, 2023 Sep 06, 2023

Copy link to clipboard

Copied

did you remove the previous listener?

Votes

Translate

Translate

Report

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
Explorer ,
Sep 07, 2023 Sep 07, 2023

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?

Votes

Translate

Translate

Report

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 Expert ,
Sep 07, 2023 Sep 07, 2023

Copy link to clipboard

Copied

yes, you need to do that:

 

stage.removeEventListener(KeyboardEvent.KEY_DOWN, fl_KeyboardDownHandler);

Votes

Translate

Translate

Report

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
Explorer ,
Sep 07, 2023 Sep 07, 2023

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.

Votes

Translate

Translate

Report

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 Expert ,
Sep 07, 2023 Sep 07, 2023

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

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