Keyboard Event with multiple functions
Most flash games and interactive animations that use keyboard events are made to respond in different ways to different keys.
I am working on games for toddlers, who basically just bang on the keyboard indiscriminately. The trouble I'm having is setting up keyboard event listeners (key_up) that each perform different function.
We're talking games like: when key pressed, ducky dances; when key pressed, doggy dances; when key is pressed, ducky and doggy go to sleep. I've attempted removing the listener before adding the next one:
stage.addEventListener(KeyboardEvent.KEY_UP, doSomething);
function doSomething(evt:KeyboardEvent):void
{make it do something;
stage.removeEventListener(KeyboardEvent.KEY_UP, doSomething);}
stage.addEventListener(KeyboardEvent.KEY_UP, doSomethingElse);
function doSomethingElse(evt:KeyboardEvent):void
{make it do something else;
stage.removeEventListener(KeyboardEvent.KEY_UP, doSomethingElse);}
Figured by removing it, I'd be able to reassign it to something else further down the line. Clearly, this is not how things work and I'm wrecking my brain trying to sort out how it works then. What's the logic of it?
Some thoughts are:
1 - maybe if i set the priority of the functions, things will run as desired? Though so far, no luck.
2 - maybe if I don't set the listener to the stage, but to the mc that will be affected, it would work ... but I thought all keyboard events MUST be set to listen to the stage. If not, then is the process of setting them to a mc the same? And if a mc is part of multiple functions, wouldn't that change that mc throughout?
How exactly would using keyboard events in this manner work?