I want to display a popup menu when the user clicks in a certain spot
in application:
private function showContextMenu(e:MouseEvent):void {
var menuData:Array = new Array();
// populate menuData
var itemMenu:Menu = Menu.createMenu(null, menuData, true);
itemMenu.show(e.stageX, e.stageY);
}
This works fine. However, if the user clicks close to the bottom or
right margin of the application, the menu is cut off.
I'd like to do something like this:
private function showContextMenu(e:MouseEvent):void {
var menuData:Array = new Array();
// populate menuData
var itemMenu:Menu = Menu.createMenu(null, menuData, true);
// how to tell a Menu to measure its width and height before
// displaying it?
var x:Number = e.stageX;
var y:Number = e.stageY;
if (x + itemMenu.width > this.stage.width) {
// show menu to the left of the cursor
x -= itemMenu.width;
}
if (y + itemMenu.height > this.stage.height) {
// show menu above the cursor
y -= itemMenu.height;
}
itemMenu.show(x, y);
}
It appears that the width and height are 0 prior to calling show().
Is there any way to measure the menu before drawing it?
Thanks,
Karl