Yeah, this is really poorly documented so be aware this could easily change in 2.0.  Note that even though the Menu is supposed to use a TreeDataProvider I had to use the MenuDataProvider interface which we haven’t even documented in the ASDoc from what I saw (but essentially imagine the TreeDataProvider where xxxTreeItem is replaced with xxxMenuItem.

 

Here’s a sample:

 

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">

 

<mx:Script>

<![CDATA[

private function getTopMenus() : Void   

{

  var dp = menuBar.dataProvider;

  for (var i = 0; i < dp.getChildNodes().length; i++)

            alert(dp.getMenuItemAt(i).getProperty("label"));

}

]]>

</mx:Script>

 

<mx:MenuBar id="menuBar">

  <mx:dataProvider>

  <mx:XML>

    <menu label="File">

      <menu label="item 1" />

    </menu>

    <menu label="Edit">

      <menu label="item 2" />

    </menu>

    <menu label="View">

      <menu label="item 3" />

    </menu>

  </mx:XML>

  </mx:dataProvider>

</mx:MenuBar>

 

<mx:Button click="getTopMenus()" />

 

</mx:Application>

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Krueger
Sent: Wednesday, July 13, 2005 10:41 AM
To: [email protected]
Subject: [flexcoders] MenuBarItem label.

 

Hello,

 

            I have a menu bar in my application and I am trying to not hard code the fact that the forth menu item is the tools menu that I need to dynamically set the menu items on.  Instead I would like to be able to loop through all the MenuBarItems and look at their names to find the one that is labeled tools.  I have tried a ton of different things but have been unsuccessful in being able to find the right syntax to get that label.

 

This is what I currently have.

 

for (var i:Number=0; i<5 ; i++)

{

            var currentMenu:Menu = theMenuBar.getMenuAt(i);

            mx.core.Application.alert(currentMenu.id);

            mx.core.Application.alert(currentMenu.value.toString());

}

 

Any suggestion would be much appreciated.

 

 

Thanks

 

 

Jeff

 



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to