开发者

How do I make menu items with children in a menubar selectable in Flex 3?

If I have a menubar that has an XML datasource like:

<mx:XMLList id="menuList">
    <menuitem label="Parent1">
        <menuitem label="Child1">
            <menuitem label="SubChild1" />
            <menuitem label="SubChild2" />
        </menuitem>
        <menuitem label="Child2" />
    </menuitem>
    <menuitem label="Parent2" /开发者_如何学Python>
</mx:XMLList>

How can I make it so that clicking on Child1 will cause a click event despite it having children?


You can add MouseEvent.CLICK Listener to the Menu and remove the MenuEvent.ITEM_CLICK listener.Sample Code:

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; */
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜