Flex中使用ContextMenu - 添加,动态改变, 响应.

Categories: Flex; Tagged with: ; @ March 26th, 2009 11:31

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

\ 这里是通用的:

		_menu = new ContextMenu();
		_menuAddTopOU = new ContextMenuItem(RM.getString(BUNDLE_OUSETUP, "ous.menu.addTopOU"));
		_menuAdd = new ContextMenuItem(null, true);
		_menuEdit = new ContextMenuItem(null);
		_menuRemove = new ContextMenuItem(null);
		
		_menu.customItems.push(_menuAddTopOU);
		_menu.customItems.push(_menuAdd);
		_menu.customItems.push(_menuEdit);
		_menu.customItems.push(_menuRemove);
		_menu.addEventListener(ContextMenuEvent.MENU_SELECT, onMenuSelected);
		_menu.addEventListener(Event.SELECT, onMenuItemSelected);
		
		_treeOUs.contextMenu = _menu;

	// Menu打开后动态改变菜单内容
	private function onMenuSelected(event:ContextMenuEvent):void {
		...
		_menuAddTopOU.enabled = !tempNew; // add Top ou
		_menuAdd.enabled = (_treeOUs.selectedItem != null) && (!_editorOU.editable);	// add ou
		if(_menuAdd.enabled) {
			_menuAdd.label = RM.getString(BUNDLE_OUSETUP, "ous.menu.add", [currentOU.nameFullLocalized]);
		}else {
			_menuAdd.label = RM.getString(BUNDLE_OUSETUP, "ous.menu.selectOneFirst");
		}
		
		..
	}

	// 选中Menu中某item后响应
	private function onMenuItemSelected(event:Event):void {
		if(event.target == _menuAddTopOU) { // 增加顶级部门
			onAction(_actionAddTopOU, null);
		}else ...
	}



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