Copy link to clipboard
Copied
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.
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
...Copy link to clipboard
Copied
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");
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now