1 Reply Latest reply on Dec 31, 2012 8:52 AM by kvanderwende

    Menu Bar with dataprovider in XML format


      Good day!


      Been working with flex for quite a while now and I must say it has been quite enjoyable. Unfortunately, I've stumbled upon a bit of a problem here and was hoping if someone could help me out. See I have this mxml which contains a menu bar, some containing sub menus while others do not.

      The data provider for that menu bar is retrieved from a action script file lets say

      menubar dataprovider = "{actionscriptfile.menubar}"

      the menubar variable inside the acrtionscript file is in XMLLIstCollection format


      ex. menuBarCollection = new XMLListCollection(XMLList(

      '<menuitem label="Go to">' +

      '<menuitem label="Home Page" />'



      This seems to be working just fine. However now, I want to serparate this actionscript from the menu items. I would like to place them inside an xml file which will be

      used to populate the menuBarCollection.


      I've tried using var request = new URLRequest("MenuXML.xml");

             var loader = new URLLoader();

             loader.load(request); <--inside the actionscript.

      However nothing is being displayed inside the menu bar.


      The xml file contains.

      MenuXML.xml file

      <?xml version="1.0" encoding="UTF-8"?>

      <menuitem label="Go to">

      <menuitem label="Home Page" />



      Any help on how this can be done will be greatly appreciated.

        • 1. Re: Menu Bar with dataprovider in XML format

          I had the same problem.  I was debugging and saw that my data was there it was just a matter of HOW to get it out.  I am not sure if this is the correct way of doing it but after reading posts on how to use an XML file for the dataProvider for everything BUT a MenuBar this is what I came up with:


          private function init():void
              var xml:XML;
              var urlRequest:URLRequest = new URLRequest("assets/menu.xml");
              var urlLoader:URLLoader = new URLLoader();
              urlLoader.dataFormat = URLLoaderDataFormat.TEXT;
              urlLoader.addEventListener(Event.COMPLETE, function (evt:Event):void
                      xml = new XML(evt.target.data);
                      menuBarCollection = new XMLListCollection(xml.children());


          I put the event handler inline but it could be a separate function.  The part I was missing was ".children()".  I eventually found that in an ActionScript example of displaying data from an XML file in an AdvancedDataGrid.