`
tw5566
  • 浏览: 460540 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

flex4 创建右键菜单的bug

XML 
阅读更多

   当使用

<s:Panel id="mainPanel" skinClass="spark.skins.spark.SkinnableContainerSkin" visible="false" width="1029" >

<mx:Tree x="10" y="1" width="247" height="457" id="tree_deps" dataProvider="{treeData.dep}" labelField="@name" showRoot="false" labelFunction="tree_labelFunc" mouseOut="this.contextMenu =null " mouseOver="initTree()"></mx:Tree>
</s:Panel>


============================================
以下是方法:

//显示子节点个数
private function tree_labelFunc(item:XML):String {
	var children:ICollectionView; 
	var suffix:String = ""; 
	if (tree_deps.dataDescriptor.isBranch(item)) { 
		children = tree_deps.dataDescriptor.getChildren(item); 
		suffix = " (" + children.length + ")"; 
	} 
	return item[tree_deps.labelField] + suffix; 
} 

//在全局上,定义三个栏目
private var MyMenu:ContextMenu = new ContextMenu();
//初始化开始了 
public function initTree():void{
	var menu1:ContextMenuItem = new ContextMenuItem("发送消息");
	var menu2:ContextMenuItem = new ContextMenuItem("查看资料");
	var menu3:ContextMenuItem = new ContextMenuItem("删除好友");
	
	MyMenu.customItems.push(menu1);
	MyMenu.customItems.push(menu2);
	MyMenu.customItems.push(menu3); 
	
	//让这三个栏目监听点事件
	menu1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menudraw);
	menu2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menudraw);
	menu3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menudraw);
	
	tree_deps.contextMenu = MyMenu;
	MyMenu.hideBuiltInItems();
}
//选择选择到了右键栏目,改干点啥
private function menudraw(event:ContextMenuEvent):void {
	//var label:Label = event.contextMenuOwner as Label;
	var menuItem:ContextMenuItem = event.target as ContextMenuItem;
	Alert.show("---您选择了:"+menuItem.caption);
	//label.text =menuItem.caption; 
}

 

 

 

以上这样在面板中绑定右键菜单失败,后来发现须在<s:panel>标签里面添加一个属性mouseEnabled="true"即可

分享到:
评论
1 楼 359126613 2013-09-26  
你要是在s:Panel 加上title他也不会显示。。。

相关推荐

Global site tag (gtag.js) - Google Analytics