Be a Supporter!

Flash As3 Button Error :s

  • 289 Views
  • 3 Replies
New Topic Respond to this Topic
CyberXR
CyberXR
  • Member since: Aug. 22, 2008
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Flash As3 Button Error :s 2010-03-13 13:11:40 Reply

I got a little problem with my game that I am about to create.

The game got two frames: a titleframe and a play frame (which is the actual game). On the titleframe I got a button that leads to the playframe. When I click it everything seems to work: I get to the playframe and everything runs. Tho it seems that the keybord inputs wont work until I click on the screen with the mousepointe once more. I cant move my character and I cant fire any bullets, but when I click anywhere on the screen once everything runs.

What can the problem be? Have never seen it before. Any suggestions? (sorry for a bad explanation)


Check out the coolest Donkey Kong Game on NG!
http://www.newgrounds.com/portal/vi ew/459064
100 posts @ Posted at: 9/15/08 07:36 AM http://www.newgrounds.com/bbs/topic /969232

BasV
BasV
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 23
Game Developer
Response to Flash As3 Button Error :s 2010-03-13 13:24:40 Reply

this has to do with the stage's focus. To prevent this, you can use something like this:

[code]
addEventListener(FocusRequestEvent.REQUE ST_FOCUS, focusRequestHandler);
private function focusRequestHandler(e:FocusRequestEvent)
:void {
stage.focus = InteractiveObject(e.target);
}
[/code]

BasV
BasV
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 23
Game Developer
Response to Flash As3 Button Error :s 2010-03-13 13:27:12 Reply

At 3/13/10 01:24 PM, BasV wrote: this has to do with the stage's focus. To prevent this, you can use something like this:

Oops! I accedentally gave you the wrong code from my project, that code is used by classes that actively want to request focus. If you want the focus to go to the stage after any mouse click, you can listen to a MouseEvent.MOUSE_DOWN Event instead, and do something like:

[code]
private function mouseDownHandler(e:MouseEvent):void {
stage.focus = stage;
}
[/code]

that way, the focus always returns to the stage. You might want to make sure the mouse events of other classes are handled before this event though.

CyberXR
CyberXR
  • Member since: Aug. 22, 2008
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Flash As3 Button Error :s 2010-03-13 16:11:15 Reply

At 3/13/10 01:27 PM, BasV wrote:
At 3/13/10 01:24 PM, BasV wrote: this has to do with the stage's focus. To prevent this, you can use something like this:
Oops! I accedentally gave you the wrong code from my project, that code is used by classes that actively want to request focus. If you want the focus to go to the stage after any mouse click, you can listen to a MouseEvent.MOUSE_DOWN Event instead, and do something like:

[code]
private function mouseDownHandler(e:MouseEvent):void {
stage.focus = stage;
}
[/code]

that way, the focus always returns to the stage. You might want to make sure the mouse events of other classes are handled before this event though.

Thank you BusV, great information. I have read the book ACtionscript 3.0 game programming university, but cant remember that this was mentioned anywhere =) Thank you


Check out the coolest Donkey Kong Game on NG!
http://www.newgrounds.com/portal/vi ew/459064
100 posts @ Posted at: 9/15/08 07:36 AM http://www.newgrounds.com/bbs/topic /969232