Select to view content in your preferred language

Header Menu Bar Drop down

1725
15
Jump to solution
01-18-2012 06:44 AM
KevinCressy
Emerging Contributor
Hi,

I would like to add a couple of menu items on a menu bar in the header of my flex viewer application.  These would include "Links" and other hyperlinks that are useful on my project.

I have looked at implementing this using MenuBar (see here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/MenuBar.html) by adding the code example to HeaderControllerWidget.mxml however while I have managed to get a "box" where the menu should be - I don't actually get a menu to appear.

I am not sure if I am adding this to the wrong file or if there is something else I am missing.

Any help appreciated.
Tags (2)
0 Kudos
15 Replies
KevinCressy
Emerging Contributor
Thanks Robert - I have tagged the posts.

Cheers,

Kevin
0 Kudos
MartynSmith
Emerging Contributor
I like this menu bar edit! have implemented it.  Is there a way to have the XML data for the menus in a seperate file instead of embedded in the headercontroller.mxml?  that way it could be updated without re-compiling?
0 Kudos
KevinCressy
Emerging Contributor
Kevin,


  I realized that I forgot to comment one area, and left some unused stuff in the code. Here is an updated version:



Hi Robert,

Hope you can help I am sure this is an easy fix again.

I have been playing with the menu's, rearranging and adding sub menu's etc.  I have managed to construct the menus as I would like them however the URL link is not working (I want some of the menu options to open external pages).  At the moment the default message box is opening rather than the links to the external sites (i.e. BBC and Sky).

I have provided my code below.  Any idea where I am going wrong?


//Code Added
   [Bindable]
   public var menuBarCollection:XMLListCollection;
   
   private var menubarXML:XMLList =
    <>
     <menuitem label="Document Links" data="top">
      <menuitem label="MenuItem 1-1" data="1-1">
       <menuitem label="MenuItem 1-1-1" groupName="one" data="1-1-1"/>
       <menuitem label="MenuItem 1-1-2" groupName="one" data="1-1-2"/>
      </menuitem>
      <menuitem type="separator"/>
      <menuitem label="MenuItem 1-2" data="1-2">
       <menuitem label="MenuItem 1-2-1" groupName="two" data="1-2-1"/>
       <menuitem label="MenuItem 1-2-2" groupName="two" data="1-2-2"/>
      </menuitem>
     </menuitem>
     <menuitem label="Other Links" data="top">
      <menuitem label="BBC Site" data="2-1"/>
      <menuitem type="separator"/>
      <menuitem label="Sky Site" data="2-2"/>
     </menuitem>
    </>;

//End Code Added 


//Code Added
   // Event handler for the MenuBar control's itemClick event.
   private function menuHandler(event:MenuEvent):void  {
    // Don't open the Alert for a menu bar item that 
    // opens a popup submenu.
    if (event.item.@data != "top") {
     //If you want to be able to do something unique when a menu
     //item is clicked than you need code like this:
     switch( event.item.@data ){
      case "2-1":
       //doSomething();
       navigateToURL(new URLRequest("http://www.bbc.co.uk/"));
       break;
      case "2-2":
       //doSomethingElse();
       navigateToURL(new URLRequest("http://www.sky.com/"));
       break;
      default:
       Alert.show("Label: " + event.item.@label + "\n" + 
        "Data: " + event.item.@data, "Clicked menu item");
       break;
     }
    }
   }
//End Code Added
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Kevin,

   Sure it was my mistake trying to compare an xml node and a string:

//Code Added    // Event handler for the MenuBar control's itemClick event.    private function menuHandler(event:MenuEvent):void  {     // Don't open the Alert for a menu bar item that      // opens a popup submenu.     if (event.item.@data != "top") {      //If you want to be able to do something unique when a menu      //item is clicked than you need code like this:      switch(String(event.item.@data)){       case "2-1":        navigateToURL(new URLRequest("http://www.bbc.co.uk/"));        break;       case "2-2":        navigateToURL(new URLRequest("http://www.sky.com/"));        break;       default:        Alert.show("Label: " + event.item.@label + "\n" +          "Data: " + event.item.@data, "Clicked menu item");        break;      }     }    } //End Code Added
0 Kudos
KevinCressy
Emerging Contributor
Thanks Robert,

That has fixed it.

Regards,

Kevin
0 Kudos
MartynSmith
Emerging Contributor
I have implemented this code that Robert helped out with and it works great, and now trying to figure out how to extend its functionality.  I'm trying to build a list of URL's in the dropdown menubar where the URL changes for each year, for example:

[Dropdown menu]
>"http://example.net/1997.txt"
>"http://example.net/1998.txt"
>"http://example.net/1999.txt"
> ... etc

The setup for the menubar code shown above is static XML, but I am wondering if there is a way to programtically create this menu with a while loop so that the menu grows as more years are added, something like this:

x = "earliest year"
while x < "current year":
    URL = "http://example.net/" + x + ".txt"
    x = x + 1


Any help is greatly appreciated
0 Kudos