Flex: Tree如何展开/关闭一个节点, 并选中其孩子? 如何关闭所有的节点?

Categories: Flex; Tagged with: ; @ March 28th, 2009 10:54
_treeOUs.expandChildrenOf(currentOU, true); // 展开目录 

_treeOUs.selectedItem = ou; //选定孩子

_treeOUs.openItems = []; // 关闭所有节点;

expandChildrenOf(item:Object, open:Boolean):void
Opens or closes all the tree items below the specified item.

expandItem(item:Object, open:Boolean, animate:Boolean = false, dispatchEvent:Boolean = false, cause:Event = null):void
Opens or closes a branch item.

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 ...
	}

AIR: NativeMenu Separator, 右键菜单分割线

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

菜单中的分割线: 通过将 NativeMenuItem 构造函数中的 isSeparator 属性设置为 true 创建一条分隔线。

		_menu = new NativeMenu();
		_menuAddTopOU = new NativeMenuItem(RM.getString(BUNDLE_OUSETUP, "ous.menu.addTopOU"));
		_menuAdd = new NativeMenuItem();
		_menuEdit = new NativeMenuItem();
		_menuRemove = new NativeMenuItem();
		_separator = new NativeMenuItem(null, true); //分割线

		_menu.addItem(_menuAddTopOU);
		_menu.addItem(_separator);
		_menu.addItem(_menuAdd);
		_menu.addItem(_menuEdit);
		_menu.addItem(_menuRemove);
		_menu.addEventListener(ContextMenuEvent.MENU_SELECT, onMenuSelected);
		_menu.addEventListener(Event.SELECT, onMenuItemSelected);
		_treeOUs.contextMenu = _menu;

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);
		}
	}

关于FlexBuilder的Event注释

Categories: Flex; Tagged with: ; @ March 15th, 2009 10:28

如果某个类派发某事件, 我们通常使用如下注释:

/** * Dispatched when …. * @eventType com.events.MyEvent.EVENT_TEST */
[Event(name=”myEvent” type=”com.events.MyEvent”)]

 

在使用new testr().addEvent…时提示的Const是错误的.MyEvent.MY_EVENT

解决方法:

[Event(name=”eventTest” type=”com.events.myevent”)]
此时的提醒为MyEvent.EVENT_TEST
[]中的name应与Event中的const的名字 如EVENT_TEST:String = "myEvent"; 中的EVENT_TEST对应 ,’_"后的字母保留大写去掉下划线->eventTest即可.

 

注意: Flex框架中的事件, 其Const 与String的name都是想对应的.

==>不得不承认 这样子比较挫<==

所以在编写自定义事件时, 最好也遵守这个不成文的规定:

public static const EVENT_EO_EDITOR:String = "eventEoEditor";

而不是随便乱写一个String, 这样便于在其他派发该事件的类中编写事件注释.

Newer Posts <-> Older Posts



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