donderdag 19 mei 2011

Keyboard focus loss

A while ago I posted the problem with a container that loads a swf.
There is no problem, when you keep de swf displayed, but if a user clicks it and you take it off the stage, it takes keyboard focus (and all other focus) with it.
There is (as always) a simple solution:
Handle all key-events in the container or a seperate class and add this:

stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler);
private function MouseDownHandler(evt:MouseEvent):void
{
   stage.focus = this;
}
And presto you have focus on this class.
This might cause a problem with other focus events, which need focus to be on the loaded swf, but for now it works fine with me..