Skip to main content
Participant
June 24, 2013
Answered

How to make a keyboard navigating multiple choice list in Flash and control it through actionscript?

  • June 24, 2013
  • 1 reply
  • 430 views

i am making an rpg style game in actionscript 3.0 and i want to make a multiple choice list. I know how to make the list with buttons and how to control it. My question is, how do you make a list that can be navigated using the keyborad arrows? What i am after is being able to hit up, and down to highlight the buttons and enter to chose the button.

This topic has been closed for replies.
Correct answer Ned Murphy

You'll need to make the buttons as movieclips so that you can control which display state they are in (highlighted versus not).

Then you need to set up a listener for the keyboard keys so that you can have the selected button change and the execute if the Enter is pressed.  Here is a basic setup for a keyboard listener that shows how to detect the three keys you mentioned...

stage.addEventListener(KeyboardEvent.KEY_DOWN,keyIsDown);


function keyIsDown(e:KeyboardEvent):void  {

         if (e.keyCode == Keyboard.DOWN) {

                 trace("DOWN");

         } else if (e.keyCode == Keyboard.UP) {

                 trace("UP");

         } else if (e.keyCode == Keyboard.ENTER) {

                 trace("ENTER");

         }

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 24, 2013

You'll need to make the buttons as movieclips so that you can control which display state they are in (highlighted versus not).

Then you need to set up a listener for the keyboard keys so that you can have the selected button change and the execute if the Enter is pressed.  Here is a basic setup for a keyboard listener that shows how to detect the three keys you mentioned...

stage.addEventListener(KeyboardEvent.KEY_DOWN,keyIsDown);


function keyIsDown(e:KeyboardEvent):void  {

         if (e.keyCode == Keyboard.DOWN) {

                 trace("DOWN");

         } else if (e.keyCode == Keyboard.UP) {

                 trace("UP");

         } else if (e.keyCode == Keyboard.ENTER) {

                 trace("ENTER");

         }

}