2010-11-17 82 views
0

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

<?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 = [email protected]; 
      var menuEvent:CustomMenuEvent = new CustomMenuEvent(CustomMenuEvent.ITEM_CLICKED); 
      menuEvent.toggled = Boolean([email protected] == "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> 

+0

好了所以,现在我觉得我需要做一些数据绑定在这里我增加了一些公共瓦尔。这就是我所做的。我添加了得到改变公共VAR和IM试图这些绑定到menuXML如: 似乎不是工作,是能够绑定到它被用作这样一个数据提供程序的XML? – Neil 2010-11-17 16:56:21

回答

相关问题