Ah, this may be an interesting case.  When we do an additem in the XMLList case we use the += operator so that we can affect the original source.  However that means that we’re appending to a node which may then affect any XMLList that contains that node.  Not quite the expected behavior.  It all comes from us trying to do the “right” thing by affecting the underlying source list (all XMLLists are copies, if you try to add to an XMLList itself that doesn’t affect the “source”); but maybe in this case you’re finding a flaw in our logic.  It’d be worth filing this on our wish form, http://www.adobe.com/go/wish.

 

Matt

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Tom Bray
Sent: Tuesday, August 01, 2006 9:43 AM
To: [email protected]
Subject: [flexcoders] strange XMLListCollection behavior

 

If you run the code below, expand the folder, select a file, and click "add to list" repeatedly, items get added to both dataProviders, but I don't understand why the original tree is changing because I'm not adding items to it.  Could someone explain what's happening?  I'm less interested in fixing it than in understanding what's happening.  Thanks.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" height="400" creationComplete="init()">
   
    <mx:Script>
    <![CDATA[
        import mx.collections.XMLListCollection;
        import mx.collections.ArrayCollection;
   
        [Bindable]
        public var myData:XML=
            <catalog>
                <category name="Folder">
                    <product name="file 1"/>
                    <product name="file 2"/>
                    <product name="file 3"/>
                </category>
            </catalog>;

        [Bindable]
        public var listDP:XMLListCollection = new XMLListCollection(new XMLList());
       
        [Bindable]
        public var testDP:XMLListCollection = new XMLListCollection( new XMLList( myData.children() ) );       
   
        // Add the item selected in the Tree to the List XMLList data provider.
        private function doTreeSelect():void
        {
            if (prodTree.selectedItem)
                listDP.addItem(prodTree.selectedItem);
               
            trace( myData );
            trace( "****************" );
            trace( listDP.source );
        }

    ]]>
    </mx:Script>
   
    <mx:Tree id="prodTree" dataProvider="{testDP}" width="200" showRoot="true" labelField="@name"/>
       
    <mx:HBox>
        <mx:Button id="treeSelect" label="Add to List" click="doTreeSelect()"/>
    </mx:HBox>
       
    <mx:List id="prodList" dataProvider="{listDP}" width="200" labelField="@name"/>

</mx:Application>

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to