Be a Supporter!

keyboard events

  • 193 Views
  • 2 Replies
New Topic Respond to this Topic
voter96
voter96
  • Member since: Dec. 26, 2007
  • Offline.
Forum Stats
Member
Level 10
Musician
keyboard events 2013-03-14 14:45:08 Reply

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.


Elephants only come out at night, for they are nocturnal. If they go out during the daylight, they melt.

BBS Signature
Mattster
Mattster
  • Member since: Nov. 21, 2007
  • Offline.
Forum Stats
Member
Level 20
Game Developer
Response to keyboard events 2013-03-14 15:29:05 Reply

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

voter96
voter96
  • Member since: Dec. 26, 2007
  • Offline.
Forum Stats
Member
Level 10
Musician
Response to keyboard events 2013-03-14 16:17:56 Reply

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.

BBS Signature