是的,有一个类似的问题,但没有活动,也没有答案。
我希望使用HTTPService从外部XML文件加载数据,在同一个HTTPService的ResultEvent上,我希望他用来自XML的数据填充ArrayCollection。
我认为ArrayCollection是这个XML的理想选择。但我愿意接受建议。
XML
<?xml version="1.0" encoding="utf-8"?>
<PhotoGalleryData>
<Photo>
<id>1</id>
<name>Summer Vacation</name>
<description>In vacation</description>
<source>vacation.JPG</source>
</Photo>
<Photo>
<id>2</id>
<name>Winter Vacation</name>
<description>coold</description>
<source>vacation2.JPG</source>
</Photo>
</PhotoGalleryData>我认为getDataResultHandler()中的这个简单行已经足够填充ArrayCollection了。
<mx:HTTPService id="getData"
url="{XMLDataFileLocation}"
fault="getDataFaultHandler()"
result="getDataResultHandler()"/>
[Bindable]
private var PhotoData:ArrayCollection;
private function getDataResultHandler():void
{
PhotoData = new ArrayCollection(getData.lastResult.PhotoGalleryData.photo)
}但我想不是这样,因为为了确定我已经放置了一个绑定到ArrayCollection的列表,以查看它是否真的被填充。
<mx:List dataProvider="{PhotoData}" labelField="name"/>这个列表没有显示任何数据,因此也不像预期的那样起作用。
谢谢你的帮助。
编辑
注意事项 所使用的
<mx:List/>只是为了确保ArrayCollection确实被填充,它不会在应用程序中使用。
结果采纳Bozho的建议.
对于,Flex不再报告var类型错误,而是在我运行它之后。Adobe确实报告了这一点。
TypeError:错误#1034:类型强制失败:无法将mx.utils::ObjectProxy@22cd311转换为mx.collections.ArrayCollection。在PhotoGallery/getDataResultHandler()C:\Users\Fábio Antunes\Documents\Flex Builder 3\Photo Gallery\src\ActionScripts\PhotoGallery.as:56 at Photo图册/__getData_Gallery\src\ActionScripts\PhotoGallery.as:56()C:\Users\Fábio Antunes\Documents\Flex Builder 3\Photo Gallery\src\PhotoGallery.mxml:23 at flash.events::EventDispatcher/dispatchEventFunction() at flash.Event:EventDispatcher/dispatchEvent() at mx.rpc.http.mxml::HTTPService/[
C16]0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:403 at flash.events::EventDispatcher/dispatchEventFunction()
那么,Flash报告错误的第23行是:
PhotoData = ArrayCollection(event.result);第23行是:
result="getDataResultHandler(event)"发布于 2009-11-11 21:14:43
如果您可以使用XMLListCollection来代替ArrayCollection,那么转换结果对象的过程就更简单了。这里是一个很好的教程,解释了如何解决这个问题。
编辑:
从本教程中获得的关键是:
e4x。XML对象,将重复节点提取为XMLList,并从列表中构造一个XMLListCollection,如下所示:
私有函数httpService_result(evt:ResultEvent):void{ var xmlList:XMLList = XML(evt.result).path.to.repeating.element;xmlListColl =新XMLListCollection(xmlList);}发布于 2009-11-11 19:13:15
您可以这样简化您的脚本:
<mx:HTTPService id="getData" url="{XMLDataFileLocation}"/>
<mx:List dataProvider="{getData.lastResult.Photo}" labelField="name"/>您的XML的lastResult将是getData的根。通过检索lastResult.Photo,您将得到照片的XMLList。
https://stackoverflow.com/questions/1717354
复制相似问题