MenuBar control in Flex

February 22, 2012

Freelance Flash Developer India Flex Developer Mobile app developer Php developer India

MenuBar control is a horizontal bar of menu items which opens submenu. The submenu will be open until the user selects on other menu item, selects a submenu item,  or clicks outside the menubar area.

Here in this example I provide data for MenuBar control using  <mx:XMLList> tag.

Flex menubar code:-

<mx:MenuBar id=”myMenuBar” labelField=”@label” width=”950″ color=”#060606″ height=”30″
     itemClick=”itemClickHandler(event)” borderColor=”#1D48E8″ horizontalCenter=”0″ themeColor=”#FFFFFF”>
            <menuitem label=”first”>
                <menuitem label=”first1″   />
                <menuitem type=”separator” />
                <menuitem label=”first2″/>
                 <menuitem type=”separator” />
                <menuitem label=”first3″/>
                 <menuitem type=”separator” />
                <menuitem label=”first4″/>
            <menuitem label=”second”>
                <menuitem label=”second1″ />
                <menuitem type=”separator”/>
                <menuitem label=”second2″/>
                <menuitem type=”separator”/>
                <menuitem label=”second3″/>
                <menuitem type=”separator”/>
                <menuitem label=”second4″/>
            <menuitem label=”third”>
                <menuitem label=”third1″ />
                <menuitem type=”separator”/>
                <menuitem label=”third2″/>
                <menuitem type=”separator”/>
                <menuitem label=”third3″/>
                <menuitem type=”separator”/>
                <menuitem label=”third4″/>

Import the MenuEvent in the event class and Alert control from controls.

import mx.controls.Alert;

We can get the Index of the selected MenuBar item using myMenuBar.selectedIndex.toString() where myMenuBar is the id of the MenuBar.and Index of the selected submenu by event.index.toString() .

import mx.controls.Alert;

private function itemClickHandler(event:MenuEvent) : void
{“selected index: ” + myMenuBar.selectedIndex.toString() +
child index: ” + event.index.toString());


I appreciate if you like this post, feel free to comment, forward, RT

flex menubar, flex menu control, flex menu example, menu bar in flex, flex menu bar, how to make menu bar in flex.
flex developer India, developers in India, India web development, hire India, web developer


Loading XML in Flash AS3

January 16, 2012

1. Create the xml file, as shown below
2. In the flash file drag a datagrid component from the components panel.
3. Create new instance of the URLLoader class which loads the xml file.
4. xml file is passed to the url inside the URLRequest object.
5. Then add an addEventListener to know when the xml file is completely loaded, we register a COMPLETE event and have it call a function.
In the function we access loaded data through URLLoader ‘s data property.and assign this to XML object.
difference between XMLList and array is that in XMLList length()  is a property.
6. Populate any data driven component including a data grid we have to create an instance of a DataProvider class .
Each time the loop runs xml data is added inside of the griddata provider using addItem({name:value})shorthand notation to create a generic object, name value pairs seperated by a “: ” this data is then set to the datagrid. Freelance flash  developer Bangalore

Loading XML in Flash AS3 code goes here:

var imagesXML:XML;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest(“picts.xml”));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(evt:Event):void
imagesXML = new XML(;
var componentProvider:DataProvider = new DataProvider();
for(var i:uint = 0; i < imagesXML.animal.length(); i++)
grid.dataProvider = componentProvider;

grid here is the instance name of datagrid component on stage. Make sure flash has imported

The xml file is as follows:

<description>bunnies are cute</description></animal>
<description>dogies are lovely</description></animal>
<description>elephant is big</description></animal>
<description>frog is green</description></animal>
<description>butterflies are colorful</description></animal>
<description>kittys are cute</description></animal>


Did you like this post? Please give me a boost, Appreciate your valuable comments, and constructive criticism :-).