如果我有一个具有XML数据源的菜单栏,如:
<mx:XMLList id="menuList">
<menuitem label="Parent1">
<menuitem label="Child1">
<menuitem label="SubChild1" />
<menuitem label="SubChild2" />
</menuitem>
<menuitem label="Child2" />
</menuitem>
<menuitem label="Parent2" />
</mx:XMLList>
如何点击Child1会导致点击事件,尽管它有孩子?
答案 0 :(得分:0)
您可以将MouseEvent.CLICK侦听器添加到菜单中,然后删除MenuEvent.ITEM_CLICK侦听器。示例代码:
var myMenu:Menu=Menu.createMenu(null, myMenuData, false);
myMenu.labelField="@label"
// Add an event listener for the itemClick event.
//myMenu.addEventListener(MenuEvent.ITEM_CLICK, itemClickInfo);
myMenu.addEventListener(MouseEvent.CLICK, itemMouseClickInfo);
// Show the menu.
myMenu.show(225, 10);
itemMouseClickInfo
// The event listener for the mouse click event.
private function itemMouseClickInfo(event:MouseEvent):void
{
ta1.text="event.type: " + event.type;
var menuItems:Menu=Menu(event.currentTarget);
menuItems.hide();
/* ta1.text+="\nevent.index: " + event.index;
ta1.text+="\nItem label: " + event.item.@label
ta1.text+="\nItem selected: " + event.item.@toggled;
ta1.text+= "\nItem type: " + event.item.@type; */
}