Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Help With KeyListeners



I'm working on a side-scrolling game in Flash 8, and I'm having some serious trouble with my "keyListener.onKeyUp". In only seems to be able to detect the last key that is up (so if someone presses right+up-right-up, it will only notice that the up key was released). This is creating a problem. Anyway, is there any possible way to tell the keyListener to only listen for a single key to be released? As in, some way to say "when the user releases the up key..."



ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 07-11-2006, 04:48 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

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

Copyright © 2005-08 www.BigResource.com, All rights reserved