KeyListeners When Is Enough, Can I Have Too Many? Is There A Better Way?
I'm trying to control my flash file via the keyboard to simulate a menu system.
I am using addListener to detect the keyboard imputs and then reacte to them.
In the first frame I define the keyListener's that I will use i.e.
keyListenerUp
keyListenerDown
keyListenerLeft
keyListenerRightCountry
keyListenerRightLanguage
One example
Code:
var keyListenerUp:Object = new Object();
keyListenerUp.onKeyDown = function() {
if (Key.getCode() == Key.UP) {
trace("up");
prevFrame();
}
};
Key.addListener(keyListenerUp);
At the first menu to select your country, first choice is English, I want to allow down and right but not up or left so I have this on the frame.
Code:
Key.removeListener (keyListenerUp);
Key.removeListener (keyListenerLeft);
Key.addListener (keyListenerRightCountry);
Key.addListener(keyListenerRightLanguage);
I have different Listeners for going right as I wish to go to a label and by pass other frames.
Now if the user pressed down it would go to the next frame, and hilight France, the frame would have the following code.
Code:
Key.removeListener (keyListenerRight);
Key.removeListener (keyListenerLeft);
Key.addListener(keyListenerUp);
Key.removeListener (keyListenerRightCountry);
Key.removeListener (keyListenerRightShape);
This now allows it to go back up, continue down but not go forward (left) as I am only doing English for this project.
As you can see I'm going to end up with many many keyListeners to cover each different reaction and I will be turning off more and more Listeners as the movie develops.
Is this ok to continue developing like this or is there a better way.?
Thanks,
Ross