I have noticed some weird behaviour when working with XML vars and
XMLListCollections.

I have an xml variable that I am looping through using a for each
loop.  I want to separate the xml into 2 seperate lists based on a
value so as I loop through, I am adding each xml node to 2 different
XmlListCollections.

Here is my code:

// myXML is an xml var declared elsewhere in the program
var xlc1:XMLListCollection = new XMLListCollection();
var xlc2:XMLListCollection = new XMLListCollection();
                
for each(var x:XML in myXML.MyNode){

    if(x.NodeStatus == 0) 
        xlc1.addItem(x);
   else if(x.NodeStatus == 1)
        xlc2.addItem(x);

The problem is that the original xml var is getting modified.

Say for example that my original myXML variable contains 10 nodes, and
there are 7 nodes that have a NodeStatus of 0 and 3 nodes that have a
NodeStatus of 1.  My 2 XMLListCollection vars contain 7, and 3 nodes
respectively as would be expected.

However, the original myXML var now contains 9 extra nodes!  19 nodes
in total.  Flex somehow is adding all these nodes back onto the
original xml var except for 1 node from each of the categories.  So in
other words, the original XML var contains all the newly added nodes
minus 2.

Is this a bug in Flex? Shouldn't the XMLListCollection just contain
pointers back to the original XML var?











                                        apXLC.addItem(x);
                                else if(x.ProjectStatus == 
ProjectStatus.PROPOSED)
                                        ppXLC.addItem(x);
                        }

Reply via email to