Using a MenuBar in flex 2.0 – Step 1

There are many great things about flex, and the flash 9 player, and actionscript 3…

I’m not brand new to flash, or flash development, i’ve never done anything truly amazing with it, but i’ve done what had to be done… it was always a pain… i’m so glad that flex 2.0 has released, i knew it would eventually get to this, and i can’t wait for it to just keep getting better…

A great tool that makes the web even more look like a true desktop application is the use of the it’s a fantastic addition, and i haven’t had a chance to look at the actionscript that it generates, but i know that i love it and it’s capabilities… i will soon be blogging on make the menu dynamic, and bringing the xml in from a query generated in coldfusion, but for now i’ll start rather simply… I can’t remember where i found this but it is a great thing!

View Example

Download Example

First things first,

1. Make your Script tag

2. import Classes

3. Create vars

4. Create 2 function —-One will be called when the menu item is clicked —-One will be called on the load of the app.

5. Create Your and Bind it










import mx.controls.Alert;

import mx.collections.*;




public var menuBarCollection:XMLListCollection;

private var menubarXML:XMLList =


<menuitem label=“File”>

<menuitem label=“Login” data=“mnuLogin”/>

<menuitem label=“Exit” data=“mnuExit”/>



4. Create 2 function


private function menuHandler(event:MenuEvent):void {“Label: “ + event.item.@label + “\n” + “Data: “ + event.item.@data + “\n”, “Clicked menu item”);


private function setUp():void{

menuBarCollection = new XMLListCollection(menubarXML);


5. Create Your MenuBar and Bind it







I worked on trying to get the xml to import from a cfc last night for about 4 hours… it really bites when there is no book for some of the stuff you want to do… so you figure it out, it takes you forever, then other people act like it’s soooo easy to do, because time goes on, people write about it, people learn more, and the community grows… i’m glad i can be a part of it, and for some reason i like the learning other things that arent written about, it keeps me alive and interested.

i’ll write later about importing the xml from a cfc file.

3 comments on this post.
  1. Paulo:

    Hi, I’m trying to put icons in all menu items, but no success.
    Do you know how can I do this?
    With iconField only the root items seams to work.

  2. admin:

    unfortunately i’ve never tried to put icons in the menu sorry.

  3. Ian:

    Thanks a bunch for this brief tutorial! I was about to pull my hair out trying to figure out how to get this stupid menu bar set up.

    A note for others reading this: Beware copying and pasting the XML from here into Flex. It converts the double quotes into something that looks like a double quote but doesn’t seem to want to be recognized in valid XML.

Leave a comment