Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

What is the best method for creating user definable or user changeable keys in a flash game?

Edit: I meant, user changeable keys. Not user changeable flash buttons. Why would a user need to change the graphic of a button in a game?

share|improve this question
    
What should be changeable? The look, the position, the label? Please add some information to your question about what you're trying to do. –  bummzack Aug 27 '10 at 6:38
2  
I'm stuck between you meaning buttons as GUI elements and keyboard 'buttons'. –  The Communist Duck Aug 27 '10 at 8:02
    
@The Communist Duck: Good point. I didn't even think about that. I guess we both agree that some clarification is needed here. –  bummzack Aug 27 '10 at 8:03
    
I think it's pretty safe to assume keyboard keys –  Bart van Heukelom Aug 27 '10 at 9:28
    
Just to make sure, when you say "user-definable" you mean definable by the person playing your Flash game (i.e. the player), and not definable by you (i.e. the developer, i.e. the Flash user), right? –  Ian Schreiber Aug 27 '10 at 11:29

3 Answers 3

up vote 3 down vote accepted

I'll answer the second question, "Why would a user need to change the graphic of a button in a game?" I think it would be an awesome idea to have a game like Upgrade Complete that is focused around the user customizing and upgrading the UI. Maybe the game has a set of undifferentiated buttons, and the player has to label and customize them so that she can figure out and remember what they do?

As for custom keys? Capture their keycodes and store them, then test against those keycodes in the input logic. You'll have some sort of options screen where you can set the custom keycodes, then use the settings in the game proper instead of using constants or magic numbers for your action buttons.

The trickiest part, oddly, is displaying the custom keys' names to the user. As far as I can recall, Flash doesn't have a lookup table matching keycodes with key labels. I'm guessing you'd need to create a dictionary yourself with the most important keys, and then just refer to any special cases as something like KEY_1876.

share|improve this answer

Use the library I created, Gamepad.

share|improve this answer

You could create a class that extends Sprite or MovieClip that it's inputs are the height, width, x, y and action (function), and create a new instance of that class each time a user wants to create a new button.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.