3 Replies Latest reply on Aug 2, 2007 4:54 PM by enfantterrible-tijzQ7

    need help creating an XMLList

      I need to create an XMLList to populate a menu, because I need it to be dynamic I would like to add and remove elements with Actionscript 3. I've been able to do this via the XMLList, ie delete mBar.menuitem[x]. but I haven't been able to add an XML object I create to an XMLList.

      how can I add an XML structure like the one below to to an XMLList object:
      public var mBar:XML =
      <menuitem label="menu1" data="top">
      <menuitem label = "menuItem 1" data = "menu1"/>
      <menuitem label = "menuItem 2" data = "menu2"/>
      <menuitem label="menu2" data="top">
      <menuitem label = "menuItem 2-1" data = "menu3"/>
      <menuitem label = "menuItem 2-2" data = "menu4"/>
        • 1. Re: need help creating an XMLList
          ntsiii Level 3
          Two ways:

          XMLList is just a list of XMLNodes. XMLList has limited methods, so do your work an XML reference variable that is the root node for the XMLList nodes.

          Now you can use appendChild on the parent XML node and the child node will be added as a sibling to the XMLList nodes.

          Also, If you are going to be working only with a single level list of nodes, you can wrap it in an XMLListCollection, which has many methods for manipulationg the list:
          var xlcMyData:XMLList = new XMLList(myXMLList);

          • 2. Re: need help creating an XMLList
            enfantterrible-tijzQ7 Level 1
            Thanks for your help, I really apreciate it!!!!

            I can't seem to add my XML nodes to an XMLList that will bind with my menubar I keep getting the error :
            Data binding will not be able to detect assignments to "myXMLlist".

            The way I've tried with previously mentioned list is:
            public var myXMLlist:XMLList;
            public function initCollections():void{ (this is executed after the "ceationComplete" is fired)
            var myXMLlist:XMLList = mBar.menuitem.@*;

            I must admit my implementation of this has gone beyond reasonning and I've resorted to just trying anything... which is not a very smart way of doing things.

            What I'm I doing wrong??????????????


            • 3. Re: need help creating an XMLList
              enfantterrible-tijzQ7 Level 1
              it seems I had forgotten to make my XML var Bindable...hhhrrrrrrr

              Thanks Tracy for your help!!!!!