Hi all,

I ran into an issue with keyboard focus which I don't understand, and I
don't see detailed in the docs anywhere.

We have a site that has games in it as well as forms, so sometimes we want
game-style key handling and sometimes we want the form style, where tab or
mouse clicks change focus.

In many of our games you need to use the keyboard and mouse, and it seems as
though every time the mouse button is pressed inside our game area (a Flex
Canvas), stage.focus gets set to null, so the keyboard event listeners
attached to our Canvas don't get called.  My current hack to fix it is to
listen for FOCUS_OUT events from the Canvas and set stage.focus back to the
Canvas.  That seems to work, but I wonder:

1) why Flash (or Flex?) is setting stage.focus to null when I click on my
game Canvas, and

2) how to make a component (my game Canvas) such that I can programmatically
set it to be focused or unfocused and disable the mouse button -based focus
change.  It seems funny that I have to keep re-asserting the focus.

I tried listening for MOUSE_FOCUS_CHANGE events and cancelling the default
action of them, but those events did not fire when the focus was changed to
null.  Strange.

Another factor is that sometimes our games are loaded from other .swf files,
and then the game Canvas can't access the stage because it would be a
sandbox violation.  So it seems like I can't just attach my game key
listeners to the stage directly.  In fact this makes me wonder if my
stage.focus thing isn't going to fail as well...

I suspect I need to make my game canvas implement IFocusManagerComponent or
something, but before I spent too much time experimenting I wanted to see if
anyone already knew the Right Way to handle this.

Thanks,
Dave
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to