|
-
Navigating buttons using keyboard events
Is there way to navigate to various buttons on a stage using only the keyboard?
I have several movies (complete with cover art) on my Flash stage. I want to convert them into buttons so that anytime a user navigates to that button and presses enter, it will take them to a new frame (where I will have information about that particular movie). I know how to do this with Mouse clicks. But, this application requires users to use arrow keys in order to navigate and not the mouse.
Suggestions?
-
Huh, listen for keyboard events?
Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, doSomething);
function doSomething(e:KeyboardEvent):void
{
var keyPressed:string="";
keyPressed = e.keyCode.toString();
if (keyPressed == "something)
{
// DO SOMETHING!
}
}
-
Yeah, I have put listeners for Keyboard events on the stage. But, you might have to explain the "string" code to me. I was hoping to have all of the buttons on a single frame, and be able to navigate to each one of these buttons on one frame.
Previously, I gave each movie it's own keyframe where it was highlighted. Pressing enter on that particular keyframe will take you to the corresponding information page for that highlighted movie. However, with over 30 movie titles, that is 30 separate keyframes.
I have been told to stay away from relying on timelines to much, and instead focus on Actionscript.
-
I don't understand what your problem is.
I showed you how to test for a keyboard event, just google "actionscript 3 keycodes" and you should get the keycodes to every key on your keyboard.
You can then assign a different function to each key (ie: Hightlight movie above, below, beside, etc.)
I'd then have all my movie in a 2d array.
So your array would look something like:
["Scarface", "The Godfather", "Casino"]
["Karlito's Way", "Goodfellas", "Eastern Promises"]
["Blow", "Lord Of War", "New Jack City"]
Then you would store the current position of the highlighted movie in a variable.
Everytime you move the cursor left or right you would modify the position you're at in the array.
So for instance if the default highlighted movie is scarface, and the name of your array is "myMovies", scarface would be
myArray[0][0]
And default variables
var arrayX:int=0;
var arrayY:int=0;
Then if you hit right for instance, you would move one over so,
arrayX++;
// arrayX would then be equal to 1.
Then when you get the enter key, you can just look up where you're at in the array:
myMovie[arrayX][arrayY]
I'm not gonna write the whole code for you but that is pretty much how I would go about it.
-
I'll do some more research on the exact code, but I thought it would be something like that. Thanks for the help!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|