Code I/O

A topnotch site

5 Minutes on Adobe Flex – Accordion as Menu

1 Comment

Handling menus is cool in flex, with all the animations and affects, user experience can be lavish, but i’ll leave it to the beholder to enhance them as they want to.

Consider the listing, where we create an accordion with the menu items as shown below:


The following listing creates the accordion:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="" width="100%" height="100%"
	verticalGap="0" horizontalGap="0">
			import utility.Application;
			import mx.controls.Alert;

			[Bindable] private var menuItems:Array = ["Home", "Accounts", "Categories", "Activity", "Tools", "Help"];

			[Bindable] private var catalogMenuXML:XMLList = <>
                    <menuitem label="Register New Account">
                        <menuitem label="Automobile" data="Automobile"/>
                        <menuitem label="Bank Account" data="Bank Account"/>
                        <menuitem label="Commodity" data="Commodity"/>

                    <menuitem label="Explore">
                    	<menuitem label="Accounts" data="Accounts"/>
                    	<menuitem label="Categories" data="Categories"/>

            private function catalogMenuHandler(event:MenuEvent):void
      "Label: " + event.item.@label + "n" +
                    "Data: " + event.item.@data, "Clicked menu item");

            private function onVAccordionClick(event:MouseEvent):void
            	var ai:MxAccordianItem = as MxAccordianItem;

            	if(ai != null)
            		trace("Title --> " + ai.title);
// Put your code here to perform some actions.

	<flexlib:VAccordion id="accordion"
		headerLocation="above" width="100%" creationPolicy="all"
		resizeToContent="true" headerRenderer="component.MxAccordianHeader"
		verticalGap="0" horizontalGap="0">

		<component:MxAccordianItem title="Home"
			description="Home for your personal financial intelligence"

		<component:MxAccordianItem title="Catalog"
			description="Manage your accounts and categories"
			menubarXML="{catalogMenuXML}" menuHandlerFunction="{catalogMenuHandler}"/>

		<component:MxAccordianItem title="Activity Log"
			description="Your activities log book" />

		<component:MxAccordianItem title="Retrospect"
			description="Analyze your finances" />

		<component:MxAccordianItem title="Insight"
			description="" />

		<component:MxAccordianItem title="Bingo!"
			description="" />


The following listing is about AccordianItem

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx=""
    width="100%" height="100%"
    verticalAlign="middle" horizontalAlign="center"
    verticalScrollPolicy="off" horizontalScrollPolicy="off"

            import mx.collections.XMLListCollection;

            [Bindable] public var description:String;
            [Bindable] public var title:String;

            public var menubarXML:XMLList = null;
			[Bindable] private var menuBarCollection:XMLListCollection;

			public var menuHandlerFunction:Function;

			private function initCollections():void {
				menuBarCollection = new XMLListCollection(menubarXML);

				if(menubarXML != null)

			// This is put in place to ensure that the accordion does not show empty space when
			// a menu does not exist
			private function onResize(event:Event):void
				if(menubarXML == null)
					vmb.height = 0;
					vmb.width = 0;

	<flexlib:VerticalMenuBar id="vmb"
		width="100%" height="100%"
		showEffect="Fade" />

One thought on “5 Minutes on Adobe Flex – Accordion as Menu

  1. Hi there,
    thanks for the post. These demos are great for learning the Flex frame work and how to extend it.

    Would be really cool to see a working demo on the page to visualize the code 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s