Hello, this is my first time on a forum, I hope I do this right :puzzled:…
I am developing a game in Flash MX 2004 and I am using the onKeyDown() function with a Listener to know what key the user has pressed. I then compare that key with a letter on a block and if it is the same, the block goes up and the ball bounces on it. The problem is the last key pressed is stored somewhere and I can’t reinitialize it. For example, if the first block is an “a” block and the user pressed “a” and the second block is also an “a” block, he doesn’t have to press the key again for the second block to go up.
I would like to be able to reinitialize the key (if there were a Key.SetKey() that would be great, but that doesn’t seem to exist) or to simulate an onKeyDown() or anything else that would work…
yeah thats what I was gonna suggest…start off before the Key.onKeyDown() enter a variable = 1 or something…then when you do the Key.onKeyDown() add in variable = 2, then add in a Key.onKeyUp() and do variable = 1…that’ll reset it each time a key is pressed and should fix the problem.
Hello!
I tried what you suggested and that doesn’t work. I use : myListener.onKeyDown = function (), not Key.onKeyDown(). I don’t know if that changes anything. I remove myListener afterwards, too.
I hope you can help me
Ignore how it says PHP and not actionscript, PHP is color coded so I used to just for you example so it’d be easier to understand.
onClipEvent (enterFrame) {
(your variable) = new Object();
Key.addListener(your variable);
with (_root.your variable) {
//this "with" statement is not needed, it's only so you don't have to specify the target everytime//
mario.onKeyDown = function() {
(new variable) = "0";
if (Key.isDown(Key.RIGHT)) {
(new variable) = "1"
}
if (Key.isDown(Key.LEFT)) {
(new variable) = "2";
};
mario.onKeyUp = function() {
(new variable) = "0"
}
}
this is just a for instance, you can use any buttons or variables.