The XMLListCollection has a special design interfaces that allow it to be used correctly with databinding. The XML object does not. Remember how you use MyList.addItem(myItem) instead of myArray.push(myItem)? This is because addItem inspects data and dispatches events. It is the same thing with the XML object.
Array is used if data is static. ArrayCollection is used if data will change. XML is used if data is static. XMLCollection is used if data will change. The general rule is, if data will change, data binding is used, or you need to filter or sort the data put your array or xml into collections before binding or putting into dataproviders. HTH On 1/21/07, Andriy Panas <[EMAIL PROTECTED]> wrote:
Hello flexcoders, I ran into 2 different behaviors dependant on the type of binded data source (XML or XMLListCollection) to mx:Tree's dataProvider. Behavior #1 ---------- If I bind the data of XML type to dataProvider's mx:Tree the whenever I add the new node to XML data source at the runtime then Tree's view DOES NOT update automatically. Behavior #2 ---------- If I bind the data of XMLListCollection type to dataProvider's mx:Tree the whenever I add the new node to XML data source at the runtime then Tree's view DOES update automatically. Studying the source code of XML, XMLListCollection did not reveal to me why does this situation happen. Any thoughts? I would appreciate any opinions on this issue to get a better understanding of Flex 2 UI framework. --Code example START-- <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" verticalAlign="left"> <mx:Script> <![CDATA[ import mx.collections.XMLListCollection; [Bindable] var employeesXML : XML = <list> <department label="TV Station"> <employee label="John"/> <employee label="Bruce"/> </department> <department label="Radio Station"> <employee label="Gerald"/> </department > <employee label="George"/> </list>; [Bindable] var employeesData : XMLListCollection = new XMLListCollection(employeesXML.department); function addNewItem() : void { var newNode : XML = <employee label="Jim"/>; employeesXML.appendChild(newNode); employeesData.addItem(newNode); employeesTextXML1.text = employeesXML.toXMLString (); employeesTextXML2.text = employeesData.toXMLString (); } ]]> </mx:Script> <mx:HBox width="100%"> <mx:Tree id="employees1" showRoot="false" dataProvider="{employeesXML}" width="50%" labelField="@label"> </mx:Tree> <mx:Tree id="employees2" dataProvider="{employeesData}" width="50%" labelField="@label"> </mx:Tree> </mx:HBox> <mx:Button label="addItem" click="addNewItem()"/> <mx:HBox width="100%"> <mx:TextArea id="employeesTextXML1" height="200" width="300"/> <mx:TextArea id="employeesTextXML2" height="200" width="300"/> </mx:HBox> </mx:Application> --Code example END-- -- Best regards, Andriy mailto:[EMAIL PROTECTED] -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links