2010-11-17 114 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

回答