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.