00:00
00:00
Newgrounds Background Image Theme

wyattemy just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

keyboard events 2013-03-14 14:45:08


I'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

http://pastebin.com/0SE28PDq

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.

Response to keyboard events 2013-03-14 15:29:05


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 :)

Response to keyboard events 2013-03-14 16:17:56


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