Skip to: Site menu | Main content

Welcome to JasonHolden.com

Here you'll find information about my work and services.

Blog...

<mx:MenuBar> Gotcha.

After almost an hour and some hair pulling I finally figured this one out.

SCENARIO:I want to drive a <mx:MenuBar> from an external XML file.

Easy enough!

Here is my XML:

<root>
<menuitem label="Main Menu 1">
<menuitem label="Menu 1 Command 1"/>
<menuitem label="Menu 1 Command 2"/>
</menuitem>
<menuitem label="Main Menu 2">
<menuitem label="Menu 2 Command 1"/>
</menuitem>
</root>

My MXML:

<mx:MenuBar id="mainMenu" width="100%" labelField="@label">
<mx:XML format="e4x" source="assets/mainmenu.xml"/>
</mx:MenuBar>

No compile errors, but when I run the application i get this:

Screenshot 1

The answer is so simple, but it eluded me. The <mx:MenuBar> has a showRoot attributes that is true by default.

New code:

<mx:MenuBar id="mainMenu" width="100%" labelField="@label" showRoot="false">
<mx:XML format="e4x" source="assets/mainmenu.xml"/>
</mx:MenuBar>

Fixed:

Screenshot 2

Sometimes Flex is too easy!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Thanks for posting this, I was having the same problem.
# Posted By John | 7/27/07 8:11 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.7.002.