Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.19 / 5.00 15,412 ViewsI'm having trouble getting flash to listen to keyboard events.
I know that it's not finding any errors in my code, and that it's not detecting when I press keys or release them. I can't see anything wrong with my code
here's the code I have for detecting key presses:
function pressKey(k:KeyboardEvent){
switch (k.keyCode){
case(37) : leftKeyPush = true; break;
case(39) : rightKeyPush = true;
}
}//end of pressKey
function releaseKey(k:KeyboardEvent){
switch(k.keyCode){
case(37) : leftKeyPush = false; break;
case(39) : rightKeyPush = false;
}
}//end of releaseKey
"World" is the instance name of an object on the stage.
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.
1) You don't have a constructor... What you currently have is a function called "rotate". The class is "Rotating" so the constructor should be Rotating()
2) You are declaring methods inside your rotate method, never ever do this. Declare them out along with everything else in the Rotating class (don't forget to add public/private before "function").
Also, there is a handy Keyboard class flash.ui.Keyboard that lets you access keys like Keyboard.A, Keyboard.LEFT_ARROW etc if you want something a little cleaner than some numbers :)
At 3/14/13 03:29 PM, Mattster wrote: 1) You don't have a constructor... What you currently have is a function called "rotate". The class is "Rotating" so the constructor should be Rotating()
2) You are declaring methods inside your rotate method, never ever do this. Declare them out along with everything else in the Rotating class (don't forget to add public/private before "function").
Also, there is a handy Keyboard class flash.ui.Keyboard that lets you access keys like Keyboard.A, Keyboard.LEFT_ARROW etc if you want something a little cleaner than some numbers :)
tried your suggestions, (hurr durr I'm an idiot for not realising that the class wasn't name correctly) but the result is the same. no errors and nothing happens
Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.