简体   繁体   中英

Adobe Flex: Cannot Convert XMLList to mx.collections.IList

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.user gives you an XMLList of all user elements. You can use XMLListCollection , which implements IList , to wrap the result so you can use it as a dataprovider.

var xml:XML = new XML(event.result as String);
var list:IList = new XMLListCollection(xml.user);

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:

var user:XML = xml.user[0];

You probably are using this inside a module or a swf that you've loaded, and the loader has a different applicationDomain than the parent, and some other loaded module or swf is also using XMLList or XMLListCollection. Without more details on your architecture, I can only tell you to make sure the parent applicationDomain loads in XMLList and/or XMLListCollection before either child, or make sure they both share the parent's applicationDomain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM