Flex: menu, menu

I donโ€™t know why, but I see that the itemclick event in the menu bar does not fire unless you click on an item.

What is the clean way to handle clicks on menu items that are at the top level and have no submenu items.

For example, I want to fire an event whenever MenuItem B is pressed.

<?xml version="1.0"?>
<!-- menus/MenuBarControl.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >

    <mx:MenuBar id="myMenuBar" labelField="@label" itemClick="{itemClick(event)}" >
        <mx:XMLList>
            <menuitem label="MenuItem A">
                <menuitem label="SubMenuItem A-1"/>
                <menuitem label="SubMenuItem A-2"/>
            </menuitem>
            <menuitem label="MenuItem B"/>
        </mx:XMLList>
    </mx:MenuBar>
</mx:Application>
+3
source share
3 answers

This is design behavior. Think of it as a menu bar in your browser: clicking on top-level items such as "File", "Edit", "View", etc., just shows a pop-up window, they do not cause any action.

On the livingocs page forMenuBar

A MenuBar , . , .

MenuBar, , . . , .

- , click MenuBar parent event.target MenuBarItem, MenuBar

+1

, ,

protected function myMenuBar_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            stackIndex=event.target.data.@index;
        }

protected function myMenuBar_itemClickHandler(event:MenuEvent):void
        {
            // TODO Auto-generated method stub
            stackIndex=event.item.@index;
        }

F ,

<mx:MenuBar id="myMenuBar" labelField="@label" click="myMenuBar_clickHandler(event)" itemClick="myMenuBar_itemClickHandler(event)" >   
    <mx:XMLList>   
        <menuitem label="MenuItem A" index="0">   
            <menuitem label="SubMenuItem A-1" index="0-0"/>   
            <menuitem label="SubMenuItem A-2" index="0-1"/>   
        </menuitem>   
        <menuitem label="MenuItem B" index="1"/>   
    </mx:XMLList>   
</mx:MenuBar>  

'index'. XML , .

"ItemClick" , "Click" ().

, .

,

+3

There are many limitations to the menu bar that the bend displays. For example, I canโ€™t have a submenu, for example, the top menu of the level 1 menu of the level 2 menu of the level 3 menu ..... to counter this, you need to add an additional menu in each submenu, which is really a pain.

0
source

Source: https://habr.com/ru/post/1736454/


All Articles