My Flex app runs a service to a php page that pulls data from my database, then structures the result in an XML format. I created a new XMLList called testList outside of any functions, then when the results come back (they first come to flex as a single string holding all of the XML code) I have the following code to turn it into XML and then append to my testList:
var s:String = event.result as String;
var xml:XML = new XML(s);
testList = xml.user;
The data is used in one function, then it’s also passed to a component of mine, where I try to display the XMLList in a List (with testList as dataProvider) and I get the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@68ffa01 to mx.collections.IList.
I have a feeling it’s probably a noob error, but any help is appreciated.
E4X expressions return lists of matching XML.
xml.usergives you an XMLList of alluserelements. You can useXMLListCollection, which implementsIList, to wrap the result so you can use it as a dataprovider.The other option is to loop though the XMLList and add it to an array or whatever collection you need. If you know for sure that there is only one user, you can do this instead: