Flex4如何选择菜单栏中的菜单项

时间:2010-11-17 15:40:20

标签: actionscript-3 flex flex4

我在Spark面板中有一个菜单栏,我想通过使用Actionscript选择其中一个菜单项我不知道如何定位其中一个项目。这是我的组件代码的摘录。

<?xml version="1.0" encoding="utf-8"?>

<s:layout>
    <s:BasicLayout />
</s:layout>
<fx:Script>
    <![CDATA[
        import events.CustomMenuEvent;

        import mx.collections.ArrayCollection;
        import mx.events.MenuEvent;

        public function update(id:String):void
        {
            // This is where I would call the menu to update the button
                            // from its mediator.
        }

        protected function appMenu_itemClickHandler(event:MenuEvent):void
        {
            var data:String = event.item.@data;
            var menuEvent:CustomMenuEvent = new CustomMenuEvent(CustomMenuEvent.ITEM_CLICKED);
            menuEvent.toggled = Boolean(event.item.@toggled == "true");
            menuEvent.data = data;
            dispatchEvent(menuEvent);
        }
    ]]>
</fx:Script>

<fx:Declarations>
    <fx:XMLList id="menuXML">
        <fx:menuitem label="File">
            <fx:menuitem label="Open" data="open"/>
            <fx:menuitem label="Exit" data="exit"/>
        </fx:menuitem>
        <fx:menuitem label="View">
            <fx:menuitem label="Map" type="check" data="map"/>
            <fx:menuitem label="Flights" type="check" data="flights"/>
            <fx:menuitem label="Altitude Graph" type="check" data="altitude"/>
        </fx:menuitem>
    </fx:XMLList>
</fx:Declarations>

<s:controlBarContent>
    <mx:MenuBar id="appMenu" 
                labelField="@label" 
                showRoot="true"
                dataProvider="{menuXML}"
                itemClick="appMenu_itemClickHandler(event)"/>
</s:controlBarContent>

1 个答案:

答案 0 :(得分:0)

好的,我发现这篇文章非常符合我的要求。

Programatically enable/disable menuBar buttons in Flex 4