contextmenu stealing focus?
Hi,
I just noticed that using the context menu will take away focus fronm the application.
Here is simple example: one part is similar to the example for flash.ui.ContextMenu, the other one just performs some action on keyboard events (the keys could as well be used to move the square around)
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.events.KeyboardEvent;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
public class ctxtype extends Sprite
{
private var tf:TextField;
private var ctx:Sprite, ctxstate:Boolean;
private var contextmenu:ContextMenu;
private var contextmenu_togglecolor: ContextMenuItem;
public function ctxtype()
{
tf = new TextField();
tf.width = 200; tf.height = 20;
tf.x = tf.y = 20;
tf.border = true;
addChild(tf);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keybd);
ctx = new Sprite();
ctx.x = 20; ctx.y = 100;
showctx();
addChild(ctx);
contextmenu = createmenu();
contextmenu.addEventListener(ContextMenuEvent.MENU_SELECT, showmenu);
this.contextMenu = contextmenu;
}
private function keybd(event:KeyboardEvent):void
{
tf.appendText(String.fromCharCode(event.charCode));
}
private function showctx():void
{
ctx.graphics.clear();
ctx.graphics.beginFill(ctxstate ? 0xff0000 : 0x00ff00);
ctx.graphics.drawRect(0, 0, 30, 30);
ctx.graphics.endFill();
}
private function createmenu():ContextMenu
{
var cm:ContextMenu = new ContextMenu();
var ci:ContextMenuItem;
cm.clipboardMenu = false;
cm.hideBuiltInItems();
contextmenu_togglecolor = new ContextMenuItem('toggle color');
contextmenu_togglecolor.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, togglecolor);
return cm;
}
private function showmenu(event:ContextMenuEvent):void
{ trace('showmenu called');
// contextmenu.clipboardMenu = false;
// contextmenu.
contextmenu.customItems = [contextmenu_togglecolor];
}
private function togglecolor(event:ContextMenuEvent):void
{
ctxstate = !ctxstate;
showctx();
}
}
}
So when I start the application, I have to click into the window once, then I can start typing. Once I use the contextmenu, I seem to have to click into the window again to reenable keyboard. This is sort of an irritating user experience. Is there anything to avoid that, short of popping up a semi-transparent "please click once to restore keyboard input"?