下面这个例子给Flex的右键添加一个自定义的菜单,并且在点击菜单内容时,执行事件
copyrightMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function
(e:ContextMenuEvent){
Alert.show((e.currentTarget
as
ContextMenuItem).caption);
});
contextMenuCustomItems:
Array
= FlexGlobals.topLevelApplication.contextMenu.customItems;
contextMenuCustomItems.push(copyrightMenuItem);
|
我使用的是Flex4,如果是Flex3,需要把var contextMenuCustomItems:Array = FlexGlobals.topLevelApplication.contextMenu.customItems;
替换为var contextMenuCustomItems:Array = application.contextMenu.customItems;