Utility method for creating a menu item that will post controller commands.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4194 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-06-16 01:22:25 +00:00
parent 1ce4f4a7e4
commit b9509e434e
+29
View File
@@ -0,0 +1,29 @@
package com.threerings.util {
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
import com.threerings.events.ControllerEvent;
/**
*/
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 {
event.mouseTarget.dispatchEvent(new ControllerEvent(cmd, arg));
});
return item;
}
}
}