Adobe AIR bug with focus
Hi,
I found a bug in AIR where keyboard events are not fired after a click on a removed button
This test app reproduce the bug :
- add keyboard listeners to your stage
- add a container (a Sprite) to the stage
- add a button (for example a Sprite with buttonMode=true) to the container
- on click on the button, remove the container from the stage
now if you launch the test app, you're keyboard events are correctly fired until you click on the button.
after clicking on the button, keyboard events are not fired because the parent of the button has been removed from stage
note that if you does'nt set buttonMode=true on the button, the bug doesn't appear...
this is the code I used to produce the bug :
public class test extends Sprite
{
private var container:Sprite;
public function test()
{
container = new Sprite();
addChild(container);
var rectangleBleu:Shape = new Shape();
rectangleBleu.graphics.beginFill(0x0000FF);
rectangleBleu.graphics.drawRect(50, 30, 100, 30);
var button:Sprite = new Sprite();
button.addChild(rectangleBleu);
button.x = 200;
button.y = 200;
button.buttonMode = true;
container.addChild(button);
button.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownSprite);
button.addEventListener(MouseEvent.CLICK, onClickSprite);
container.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
container.stage.focus = stage;
stage.addEventListener(FocusEvent.FOCUS_IN, onFocus);
stage.addEventListener(FocusEvent.FOCUS_OUT, onFocus);
stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, onFocus);
stage.addEventListener(FocusEvent.MOUSE_FOCUS_CHANGE, onFocus);
trace(stage.focus);
}
private function onMouseDownSprite(e:MouseEvent):void {
trace("mouse_down");
trace(stage.focus);
}
private function onClickSprite(e:MouseEvent):void {
trace("click");
removeChild(container);
trace(stage.focus);
}
private function onKeyDown(e:KeyboardEvent):void {
trace("key: "+e.keyCode);
trace(stage.focus);
}
private function onFocus(e:FocusEvent):void {
trace(e);
}
}
This bug is very annoying because I'm writting a real time AS3 game, and if Keyboard Events are not fired, the player is blocked in a direction...
Thanks
