简体   繁体   English

Adobe Flex:无法将XMLList转换为mx.collections.IList

[英]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. 我的Flex应用程序运行一个服务到php页面的服务,该服务从我的数据库中提取数据,然后以XML格式构建结果。 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: 我在任何函数外部创建了一个新的XMLList,称为testList ,然后当结果返回时(它们首先变成包含所有XML代码的单个字符串来伸缩),我有以下代码将其转换为XML,然后追加到我的testList:

var s:String = event.result as String; var s:String = event.result as String;
var xml:XML = new XML(s); var xml:XML =新的XML;
testList = xml.user; 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: 数据在一个函数中使用,然后也传递给我的一个组件,在该组件中,我尝试在列表中显示XMLList(将testList作为dataProvider),并且出现以下错误:

TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@68ffa01 to mx.collections.IList. TypeError:错误#1034:类型强制转换失败:无法将XMLList @ 68ffa01转换为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. E4X表达式返回匹配XML的列表。 xml.user gives you an XMLList of all user elements. xml.user为您提供所有user元素的XMLList。 You can use XMLListCollection , which implements IList , to wrap the result so you can use it as a dataprovider. 您可以使用实现IList XMLListCollection来包装结果,以便可以将其用作数据提供者。

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. 另一个选择是循环遍历XMLList并将其添加到数组或所需的任何集合中。 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. 您可能在已加载的模块或swf中使用此文件,并且加载器与父级具有不同的applicationDomain,并且其他已加载的模块或swf也在使用XMLList或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. 如果没有关于您的体系结构的更多详细信息,我只能告诉您确保父子applicationDomain在任何一个子子之前加载到XMLList和/或XMLListCollection中,或者确保它们都共享父母的applicationDomain。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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