xml数据:
<?xml version="1.0" encoding="UTF-8"?>
<shuju>
<shuiguo month="Jan-04">
<apple>81768</apple>
<orange>60310</orange>
<banana>43357</banana>
</shuiguo>
<shuiguo month="Feb-04">
<apple>81156</apple>
<orange>58883</orange>
<banana>49280</banana>
</shuiguo>
</shuju>
程序代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="http.send()">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
[Bindable]
public var myData:ArrayCollection;
public function resultHandler(event:ResultEvent):void{
error.text = event.result as String;
myData = new ArrayCollection(event.result.shuju.shuiguo);
}
]]>
</mx:Script>
<!--<mx:HTTPService id="http" url="http://localhost:8080/XML2ArrayCollection/data/data.xml" useProxy="false" result="resultHandler(event)"/>-->
<mx:HTTPService id="http" url="http://localhost:8080/XML2ArrayCollection/data/data.xml" useProxy="false" result="myData=ArrayCollection(http.lastResult.shuju.shuiguo)"/>
<mx:Panel title="Line Chart" width="465" height="496">
<mx:LineChart id="chart" dataProvider="{myData}">
<mx:horizontalAxis>
<mx:CategoryAxis categoryField="month"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="apple" name="Apple"/>
<mx:LineSeries yField="orange" name="Orange"/>
<mx:LineSeries yField="banana" name="Banana"/>
</mx:series>
</mx:LineChart>
<mx:TextArea width="393" id="error"/>
</mx:Panel>
</mx:Application>
现在有一个问题我不明白:
我把那个httpservice改写成:
<mx:HTTPService id="http" url="http://localhost:8080/XML2ArrayCollection/data/data.xml" useProxy="false" result="resultHandler(event)"/>
然后添加了脚本:
public function resultHandler(event:ResultEvent):void{
error.text = event.result as String;
myData = new ArrayCollection(event.result.shuju.shuiguo);
}
这样就不行了,我测试了下,好像event.result里面没有内容,没有返回xml内容吗?谁大牛帮忙解释下。
Reference:
1. http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=charts_intro_108_12.html
2. http://hillelcoren.com/2008/09/21/flex-tip-convert-xml-to-arraycollection/
3. http://dreamweaverforum.info/flex/20292-converting-xml-file-array-collection.html
本文探讨了一个Flex应用程序中从XML数据源转换为ArrayCollection的问题。作者尝试修改HTTPService组件以使用自定义处理函数,但发现无法正确解析XML数据。文章提供了原始代码片段和修改后的版本,并寻求社区帮助来解决此问题。

被折叠的 条评论
为什么被折叠?



