Be a Supporter!

Key listeners on Apple Macintosh

  • 346 Views
  • 5 Replies
New Topic Respond to this Topic
Fion
Fion
  • Member since: Aug. 21, 2005
  • Offline.
Forum Stats
Member
Level 39
Blank Slate
Key listeners on Apple Macintosh Oct. 2nd, 2012 @ 01:51 AM Reply

Waddup Flash forum, long time no see. Doubt any old faces remember me around here haha.

I'm in need of some insight, working on a rather large flash project at the moment and for some reason I'm having some issues with my keylisteners on Macs.

When running the swf on fairly new mac the game lagged a lot when a lot of keys were pressed (lots of calls to the keyListener function), and news from someone else doing testing said it wasn't registering key presses at all on their mac. Is there any known issues with the keyboard even listener classes working properly on apples? I know for sure that the problem is in the API and not my code as removing all functionality from my keylistener function still caused the lag issue.

Any help/links would be greatly appreciated.


.

BBS Signature
64base
64base
  • Member since: Apr. 18, 2012
  • Offline.
Forum Stats
Member
Level 02
Programmer
Response to Key listeners on Apple Macintosh Oct. 2nd, 2012 @ 02:38 AM Reply

Where and when is the event listener being handled (after stage initialisation?) and what object have you attached the listener to (presuming you're using AS3)?


.

Fion
Fion
  • Member since: Aug. 21, 2005
  • Offline.
Forum Stats
Member
Level 39
Blank Slate
Response to Key listeners on Apple Macintosh Oct. 2nd, 2012 @ 05:14 AM Reply

At 10/2/12 02:38 AM, 64base wrote: Where and when is the event listener being handled (after stage initialisation?) and what object have you attached the listener to (presuming you're using AS3)?

Event listener is being attached in the document class constructor (which will later not be the document class but I think this is irrelevant) and it's being attached to the stage.


.

BBS Signature
Sandremss128
Sandremss128
  • Member since: Aug. 22, 2009
  • Offline.
Forum Stats
Supporter
Level 11
Programmer
Response to Key listeners on Apple Macintosh Oct. 2nd, 2012 @ 06:50 AM Reply

At 10/2/12 05:14 AM, Fion wrote:
Event listener is being attached in the document class constructor (which will later not be the document class but I think this is irrelevant) and it's being attached to the stage.

I think that's your problem right there. In the constructor class the stage might not be available yet; a rookie mistake.
It's only safe to use the stage keyword when you're sure stage is available. Use this standard code to get around it:

public function Constructor() {
   if(stage != null) init();
   else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(event : Event = null) : void {
   //now you can access the stage
   removeEventListener(Event.ADDED_TO_STAGE, init);
}
Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Key listeners on Apple Macintosh Oct. 2nd, 2012 @ 09:10 AM Reply

At 10/2/12 01:51 AM, Fion wrote: When running the swf on fairly new mac the game lagged a lot when a lot of keys were pressed (lots of calls to the keyListener function), and news from someone else doing testing said it wasn't registering key presses at all on their mac. Is there any known issues with the keyboard even listener classes working properly on apples? I know for sure that the problem is in the API and not my code as removing all functionality from my keylistener function still caused the lag issue.

There are no differences in listening for keys on any operating system. It's most likely the problem Sandremss128 described, but it's slightly weird that it worked fine on one machine but failed on another.

Fion
Fion
  • Member since: Aug. 21, 2005
  • Offline.
Forum Stats
Member
Level 39
Blank Slate
Response to Key listeners on Apple Macintosh Oct. 2nd, 2012 @ 09:55 AM Reply

I will certainly test out attaching it after the constructor/testing if stage had been initialized, I considered this to be the problem but assumed that it wouldn't be due to the fact that it works totally fine on pc.

Regardless, if that is causing the problem with it not working at all that might make sense but there is no reason that would cause the lag on the other device.

At 10/2/12 09:10 AM, Sam wrote: There are no differences in listening for keys on any operating system

From an Actionscript perspective no, but there is likely different communication going on between the flash player and the system depending on your OS, which would explain the otherwise bizarre concept that it works on one system but not the other.


.

BBS Signature