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.
no.
but scarces method looks a bit daunting i gotta say
on your code, before you perform any actions, ie. after all your onKey stuff and listeners and what not… before you actually DO what you want to do… put this before it
if(x!=2){
and the following just after your actions
x=2}
then close off all your key down stuff… then put an identical to your onKeyDown function but trading in Down with Upwith the following action:
{x=1}
if you give us the code you have at the moment we will be better able to demonstrate the simplicity of it
Hello!
Ok, I did what you said and it still doesn’t work. I will write the code for my onKeyDown function here but I don’t think it’s easy to understand without a lot of details (and my comments are in french…)
Anyway here it is with the stuff you told me to add :
Thanks very much, Prophet, but that doesn’t work either. I don’t know what I’m gonna do but I will try to find something.
Thanks again with your help.