是的,有一个像这样的问题,但是没有活动也没有答案。
我想使用 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 的 List 以实际查看它是否真的被填充。
<mx:List dataProvider="{PhotoData}" labelField="name"/>
而且该列表没有显示任何数据,因此无法正常工作。
谢谢你的帮助。
编辑
笔记
used 只是为了
<mx:List/>
确保 ArrayCollection 确实已填充,它不会在 App 中使用。
结果采取了博卓的建议。
随着 Bozho 的变化,Flex 不再报告 var 类型错误,但是一旦我运行它。Adobe flash 确实报告了这一点。
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] 在 PhotoGallery/__getData_result()[C:\Users\Fábio Antunes\Documents \Flex Builder 3\Photo Gallery\src\PhotoGallery.mxml:23] 在 flash.events::EventDispatcher/dispatchEventFunction() 在 flash.events::EventDispatcher/dispatchEvent() 在 mx.rpc.http.mxml::HTTPService/ http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\mxml\HTTPService。 as:290] 在 mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:193 ]在 mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43] 在 mx.rpc::AsyncRequest/acknowledge() [C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74] 在 DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\ src\mx\messaging\channels\DirectHTTPChannel.as:403] 在 flash.events::EventDispatcher/dispatchEventFunction()
好吧,Flash报告错误的第23行是:
PhotoData = ArrayCollection(event.result);
第 23 行是:
result="getDataResultHandler(event)"