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