Skip to main content
commoniq_49504929
Participating Frequently
February 6, 2019
Answered

Frame navigation with key press

  • February 6, 2019
  • 2 replies
  • 465 views

let's say from frame one I want to go to frame two. But instead of clicking on a button with a mouse, I use the key binds instead. Problem is when I press on the keys, it doesn't work.

Heres the code I tried to reenact.

import flash.events.KeyboardEvent;

import flash.ui.Keyboard;

function keyDownHandler(e:KeyboardEvent):void

{

     if (currentScene.name == "Frame 1")

     {

          if (e.keyCode == Keyboard.E)

               gotoAndStop(2);

     }

     else if (currentScene.name == "Frame 2")

     {

          if (e.keyCode == Keyboard.F)

               gotoAndStop(3);

     }

     else if (currentScene.name == "Frame 3")

     {

          if (e.keyCode == Keyboard.G)

               gotoAndStop(4);

     }

}

stop();

if (!stage.hasEventListener(KeyboardEvent.KEY_DOWN))

     stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

Thanks

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

You want to move from frame to frame, but you're checking for scenes names:

if (currentScene.name == "Frame 2")

Shouldn't it be something like:

if (currentLabel == "home")

or

if (currentFrame == 1)

?

Please let us know.

Regards,

JC

2 replies

commoniq_49504929
Participating Frequently
February 6, 2019

Wow, what a quick reply. I was still editing my post. :0

Thanks

JoãoCésar17023019
Community Expert
Community Expert
February 6, 2019

Haha!

Excellent!

You're welcome!

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
February 6, 2019

Hi.

You want to move from frame to frame, but you're checking for scenes names:

if (currentScene.name == "Frame 2")

Shouldn't it be something like:

if (currentLabel == "home")

or

if (currentFrame == 1)

?

Please let us know.

Regards,

JC