宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应

[Flex]Flex4中添加自定义右键菜单源代码示例

2016-10-13 00:16:48 点击量:7 标签: 收藏本文

下面这个例子给Flex的右键添加一个自定义的菜单,并且在点击菜单内容时,执行事件

  1. var copyrightMenuItem:ContextMenuItem = new ContextMenuItem("菜单内容", true, true);  
  2. copyrightMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,function(e:ContextMenuEvent){   
  3.     Alert.show((e.currentTarget as ContextMenuItem).caption);   
  4. });   
  5. var contextMenuCustomItems:Array = FlexGlobals.topLevelApplication.contextMenu.customItems;   
  6. contextMenuCustomItems.push(copyrightMenuItem);  

我使用的是Flex4,如果是Flex3,需要把var contextMenuCustomItems:Array = FlexGlobals.topLevelApplication.contextMenu.customItems;

替换为var contextMenuCustomItems:Array = application.contextMenu.customItems;