Hi, I am trying to sort an XMLList based on one of the attributes in the XML node. On trying this I get the following error:
TypeError: Error #1089: Assignment to lists with more than one item is not supported. Instead of XMLList if I use XMLListCollection it works fine. The thing is that I have used XMLList at lot of other places in my code as well so I cannot easily switch to XMListCollection. I would be prefer a way if I could sort the XMLList somwehow. Following is the sample code that I tried for the sorting difference between XMLList amd XMLListCollection: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import mx.collections.XMLListCollection; import mx.collections.SortField; import mx.collections.Sort; private var books:XML = <books> <book publisher="Addison-Wesley" name="Design Patterns" /> <book publisher="Addison-Wesley" name="The Pragmatic Programmer" /> <book publisher="Addison-Wesley" name="Test Driven Development" /> <book publisher="Addison-Wesley" name="Refactoring to Patterns" /> <book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" /> <book publisher="O'Reilly Media" name="Unit Test Frameworks" /> </books>; // This does not work. /* [Bindable] private var booksList:XMLList = books.children(); */ [Bindable] private var booksList:XMLListCollection = new XMLListCollection(books.children()); private function sortBooks():void { var s:Sort = new Sort(); s.fields = [new SortField("@name")]; booksList.sort = s; booksList.refresh(); tree.dataProvider = booksList; } ]]> </mx:Script> <mx:VBox> <mx:Tree id="tree" dataProvider="{booksList}" labelField="@name"/> <mx:Button click="sortBooks()" label="Sort books"/> </mx:VBox> </mx:Application>

