3 Replies Latest reply on Jun 9, 2008 2:17 PM by Garyl Woolworth

    Menu Bar click event

    josh_aries Level 1
      Hi,
      I have created an XML file and provided as the dataProvider to the menu bar control.
      How do I open the page when the user clicks on the menubar item?

      <?xml version="1.0" encoding="utf-8"?>
      <menu>
      <menuitem label="xxx">
      <menuitem label="yyy" />
      <menuitem label="zzz" />
      </menuitem>
      <menuitem label="test">
      <menuitem label="test1" />
      </menuitem>
      </menu>

      <mx:XML id="menuList" source="../assets/xml/Menu.xml"></mx:XML>
      <mx:MenuBar id="myMenuBar" labelField="@label" dataProvider="{menuList}" showRoot="false"></mx:MenuBar>

      I have a page called test.mxml. How do I associate it to test1 menuitem?

      thanks in advance.
        • 1. Re: Menu Bar click event
          NYY60504
          Josh -

          On the bar item -

          click= "menuClick(event)"

          public function menuClick(event:Event):void
          {
          // Event handler for the Click
          Alert.show(event.currentTarget.selectedItem.@label);
          //Alert should show your XML/Button label


          }

          then insert the URL as a data field in your XML like so -
          <menuitem label="test1" data=" http://www.yankees.com"/>

          Alert.show(event.currentTarget.selectedItem.@data);

          then something similar to this...

          private function menuBARGoTo():void
          {// External Nav Links
          switch (menuBar.selectedIndex.toString())
          {
          case "0":
          Alert.show("Help Is On The Way", "Pinnacol Help");
          return;
          case "1":
          var Exit:URLRequest = new URLRequest
          " http://www.yankees.com/");
          navigateToURL(Exit,"_self");
          return;
          }
          }

          or

          you can pass the selectedIndex of the Menu bar to the menuBARGoTo() method by passing the event

          click="menuBARGoTo(event)"

          and have the URLs in the method...

          Answer your question?
          • 2. Re: Menu Bar click event
            josh_aries Level 1
            event.currentTarget and then selecteditem does not showup. I am not able to get it working.
            • 3. Re: Menu Bar click event
              Garyl Woolworth Level 1
              I've posted an example of how to tie the URL into the xml list itself. Hope this helps.