您的位置:首页 > 移动开发

flex tree 添加右键菜单

2010-04-16 15:40 399 查看
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12">
<mx:Script>
<!--[CDATA[
import mx.controls.Alert;

public var newBuildMenuItem:ContextMenuItem;//菜单项变量

private function init(): void//初始化函数
{
createTreeMenuItem();
tree.contextMenu = getTreeContxtMenu();
}
public function createTreeMenuItem(): void//菜单项创建函数,并添加菜单监听器
{
newBuildMenuItem = new ContextMenuItem("新建");
newBuildMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, newBuildHandler2);
}

private function getTreeContxtMenu(): ContextMenu//将菜单项目添加到菜单中
{
var contextMenu: ContextMenu = new ContextMenu();
contextMenu.hideBuiltInItems();
contextMenu.customItems.push(newBuildMenuItem);
return contextMenu;
}
public function newBuildHandler2(event:Event):void//点击菜单执行函数
{
Alert.show("这是新建的菜单点击后执行的函数");
}
]]-->
</mx:Script>
<mx:Tree id="tree" x="31" y="10"  creationComplete="init()"></mx:Tree>

</mx:Application>


 

为tree添加右键菜单,也可为其他任何控件添加,但暂时没法去除右键自带的菜单项,虽然网上有办法去掉,但是感觉麻烦,大家又好办法提出来啊
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息