flex4 创建右键菜单的bug
?? 当使用
<s:Panel id="mainPanel" skinvisible="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"即可