Flex4中添加自定义右键菜单

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

				var copyrightMenuItem:ContextMenuItem = new ContextMenuItem("菜单内容", true, true);
				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;

posted @ 2010-12-24 14:02  魔豆  阅读(2188)  评论(0编辑  收藏  举报