Files
narya/src/as/com/threerings/util/MenuUtil.as
T
Ray Greenwell ce5caaedfe Ah, I figured out how to fix up my one issue with controllers:
The default behavior of an event is determined by the entity that calls
into the event dispatcher, so the solution was to unify the dispatch of
these events. Created a utility method in CommandEvent to do that, and
did some singlton-like hackery on the constructor to prevent folks from
thinking they can just dispatch these themselves and have it work correctly.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4317 542714f4-19e9-0310-aa3c-eee0fc999fb1
2006-08-11 01:22:50 +00:00

30 lines
872 B
ActionScript

package com.threerings.util {
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
import com.threerings.mx.events.CommandEvent;
/**
*/
public class MenuUtil
{
/**
* Create a menu item that will submit a controller command when selected.
*/
public static function createControllerMenuItem (
caption :String, cmd :String, arg :Object = null,
separatorBefore :Boolean = false, enabled :Boolean = true,
visible :Boolean = true) :ContextMenuItem
{
var item :ContextMenuItem =
new ContextMenuItem(caption, separatorBefore, enabled, visible);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function (event :ContextMenuEvent) :void {
CommandEvent.dispatch(event.mouseTarget, cmd, arg);
});
return item;
}
}
}