Flex--XML转换成ArrayCollection

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值