AIR: 通过监听ContextMenuEvent.MENU_SELECT事件 动态改变菜单内容

Categories: Flex; Tagged with: ; @ March 26th, 2009 9:47

某Tree上的menu

		_menu = new NativeMenu();
		_menuAddTopOU = new NativeMenuItem("Add Top OU");
		_menuAdd = new NativeMenuItem("Selcet one OU ls");
		_menu.addItem(_menuAddTopOU);
		_menu.addItem(_menuAdd);
		_menu.addEventListener(ContextMenuEvent.MENU_SELECT, onMenuSelected);
		_menu.addEventListener(Event.SELECT, onMenuItemSelected);
		_treeOUs.contextMenu = _menu;

监听函数:

	// Menu打开后动态改变菜单内容
	private function onMenuSelected(event:ContextMenuEvent):void {
		var currentOU:OrgUnit = _treeOUs.selectedItem as OrgUnit;
		_menuAdd.enabled = _actionAdd.enabled;
		if(_menuAdd.enabled) {
			_menuAdd.label = "Add OU in " + currentOU.nameFullLocalized;
		}else {
			_menuAdd.label = "Select one UP first";
		}
	}
	
	// 选中Menu中某item后响应
	private function onMenuItemSelected(event:Event):void {
		if(event.target == _menuAddTopOU) {
			trace("右键点击增加顶级部门");
			onAction(_actionAddTopOU, null);
		}else if(event.target == _menuAdd) {
			trace("增加子部门");
			onAction(_actionAdd, null);
		}
	}



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.