3 Replies Latest reply on Sep 20, 2008 9:23 AM by Newsgroup_User

    XMLList to XMLListCollection?

    |>AoA<|_killa
      I'm trying to convert an XMLList to an XMLListCollection because i need to remove some elements from it. But the xmllist doesnt get copied to the xmllistcollection object.

      It doesnt get shown in the Alert box.
        • 1. Re: XMLList to XMLListCollection?
          Level 7

          "|>AoA<| killa" <webforumsuser@macromedia.com> wrote in message
          news:gb2m6a$cal$1@forums.macromedia.com...
          > I'm trying to convert an XMLList to an XMLListCollection because i need to
          > remove some elements from it. But the xmllist doesnt get copied to the
          > xmllistcollection object.
          >
          > It doesnt get shown in the Alert box.
          >
          > var xml:XMLListCollection =
          > XMLListCollection(choicesArrayColl[formulaIndexArray[currentTargetIndex]]);
          >
          > Alert.show(xml.toString());
          >
          > for(var o:int = 0; o < xml.length; o++)
          > {
          > if(!formulaHandler.getBoolean(xml[o].value +
          > filledInFormulas .toString())){
          > xml.removeItemAt(o);
          > }
          > }
          >
          > this[formulaIndexArray[currentTargetIndex]].dataProvider = xml;

          I'm not sure why you need to use an XMLListCollection just to remove items,
          but you probably need to take a step back and do something like

          trace(choicesArrayCol.toXMLString())
          trace(choicesArrayCol[formulaIndexArray].toXMLString())

          and so on, and verify that the argument you're passing to XMLListCollection
          contains what you think it does. Also, you may want to try using the new
          operator

          var xml:XMLListCollection = new
          XMLListCollection(choicesArrayColl[formulaIndexArray[currentTargetIndex]]);

          HTH;

          Amy


          • 2. XMLList to XMLListCollection?
            |>AoA<|_killa Level 1
            The "new" operator worked :)

            But now when i remove an element, it also removes it for the original XMLList. I need the original one to have the default content.
            I didn't put it up as bindable or anything like that.

            EDIT: fixed it by doing var xml:XMLListCollection = new XMLListCollection(choicesArrayColl[formulaIndexArray[currentTargetIndex]].choice .copy());

            Now everything works like it should.
            Thanks alot for your help :)

            The reason why i use XMLListCollection is because it has removeItemAt while XMLList doesnt. Got an idea to remove an element another way?
            • 3. Re: XMLList to XMLListCollection?
              Level 7

              "|>AoA<| killa" <webforumsuser@macromedia.com> wrote in message
              news:gb3542$t6p$1@forums.macromedia.com...
              > The "new" operator worked :)
              >
              > But now when i remove an element, it also removes it for the original
              > XMLList.
              > I need the original one to have the default content.
              > I didn't put it up as bindable or anything like that.

              You'll need to copy all the nodes you want to keep. An XMLListCollection
              contains a _reference_ to the XMLList, so any changes you make to the
              XMLListCollection actually change the XMLList inside it.

              HTH;

              Amy