Cleaned up some issues:
- While Menu.popUpMenu() takes a DisplayObjectContainer as a parent, it will hork unless the parent is really a UIComponent. Omit that parameter from our convenience function and allow the parent to be set to the application. - Changed show() with no args to show at the mouse location. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@131 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -7,6 +7,7 @@ import flash.geom.Rectangle;
|
||||
|
||||
import mx.controls.Menu;
|
||||
import mx.core.mx_internal;
|
||||
import mx.core.Application;
|
||||
import mx.core.ScrollPolicy;
|
||||
import mx.events.MenuEvent;
|
||||
|
||||
@@ -14,6 +15,8 @@ import com.dougmccune.controls.ScrollableArrowMenu;
|
||||
|
||||
import com.threerings.util.CommandEvent;
|
||||
|
||||
use namespace mx_internal;
|
||||
|
||||
/**
|
||||
* A pretty standard menu that can submit CommandEvents if menu items
|
||||
* have "command" and possibly "arg" properties. Commands are submitted to
|
||||
@@ -45,16 +48,15 @@ public class CommandMenu extends ScrollableArrowMenu
|
||||
/**
|
||||
* Factory method to create a command menu.
|
||||
*
|
||||
* @param parent The parent of this menu.
|
||||
* @param items an array of menu items.
|
||||
*/
|
||||
public static function createMenu (
|
||||
parent :DisplayObjectContainer, items :Array) :CommandMenu
|
||||
public static function createMenu (items :Array) :CommandMenu
|
||||
{
|
||||
var menu :CommandMenu = new CommandMenu();
|
||||
menu.owner = DisplayObjectContainer(Application.application);
|
||||
menu.tabEnabled = false;
|
||||
menu.showRoot = true;
|
||||
Menu.popUpMenu(menu, parent, items);
|
||||
Menu.popUpMenu(menu, null, items);
|
||||
return menu;
|
||||
}
|
||||
|
||||
@@ -72,11 +74,27 @@ public class CommandMenu extends ScrollableArrowMenu
|
||||
y = r.y - getExplicitOrMeasuredHeight();
|
||||
|
||||
} else {
|
||||
// simply position it below the trigger
|
||||
// position it below the trigger
|
||||
show(r.x, r.y + r.height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just like our superclass's show(), except that when invoked
|
||||
* with no args, causes the menu to show at the current mouse location
|
||||
* instead of the top-left corner of the application.
|
||||
*/
|
||||
override public function show (xShow :Object = null, yShow :Object = null) :void
|
||||
{
|
||||
if (xShow == null) {
|
||||
xShow = DisplayObject(Application.application).mouseX;
|
||||
}
|
||||
if (yShow == null) {
|
||||
yShow = DisplayObject(Application.application).mouseY;
|
||||
}
|
||||
super.show(xShow, yShow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for MenuEvent.ITEM_CLICK.
|
||||
*/
|
||||
@@ -109,15 +127,6 @@ public class CommandMenu extends ScrollableArrowMenu
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Callback for MenuEvent.MENU_SHOW.
|
||||
// */
|
||||
// protected function handleMenuShown (event :MenuEvent) :void
|
||||
// {
|
||||
// // just ensure that every menu can scroll
|
||||
// event.menu.verticalScrollPolicy = ScrollPolicy.ON;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get the command for the specified item, if any.
|
||||
* Somewhat similar to bits in the DefaultDataDescriptor.
|
||||
|
||||
Reference in New Issue
Block a user