2011-02-07 45 views
0

如果我有了像XML數據源菜單欄:如何使用Flex 3中的菜單欄選擇子菜單項?

<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會,儘管有兒童它會導致click事件?

回答

0

您可以添加MouseEvent.CLICK監聽到菜單和刪除MenuEvent.ITEM_CLICK listener.Sample代碼:

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: " + [email protected] 
      ta1.text+="\nItem selected: " + [email protected]; 
     ta1.text+= "\nItem type: " + [email protected]; */ 
     }