HTTPService与xml结合绑定DataGrid
1.定义HTTPService
<mx:HTTPService id="employeeService"
url="data/employees.xml"
result="resultHandler(event)"
fault="faultHandler(event)"/>
2.初始化发送HTTPService initialize="employeeService.send()"
3.返回结果定义 private function resultHandler(event:ResultEvent):void {
employeeData = event.result.employees.employee;//event.result+employees.employee结合5
}
4.DataGrid绑定 dataProvider="{employeeData}
5.<?xml version="1.0"?>
<employees>
<employee>
<firstname>Renee</firstname>
<lastname>Dieviss</lastname>
<id>rdieviss</id>
<title>President</title>
<email>rdieviss@test.com</email>
<managerid></managerid>
<department>Corporate Team</department>
<location>San Francisco</location>
<phone>415-555-1212</phone>
<directdial>33782</directdial>
<desklocation>10-1</desklocation>
<city>San Francisco</city>
<state>California</state>
<countrycode>US</countrycode>
<postalcode>94103</postalcode>
</employee>
</employees>
完整的mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
initialize="employeeService.send()">
<!-- Code for Retrieving data via HTTPService (8:26) video
http://link.brightcove.com/services/player/bcpid1681730258?bctid=1680571179 -->
<!-- Run the application first and look at the returned data displayed in the DataGrid.
Next, add a breakpoint inside the resultHandler() and debug the application to view the returned data in the
debugger.
Finally, generate a fault by changing the url in the HTTPService object so it is mispelled and
then debug the application and look at the fault data. -->
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
// Variable to hold the results of the HTTPService call
[Bindable]
private var employeeData:ArrayCollection;
// result event handler for employeeService HTTPService call
private function resultHandler(event:ResultEvent):void {
employeeData = event.result.employees.employee;
}
// fault event handler for employeeService HTTPService call
private function faultHandler(event:FaultEvent):void {
// Add code here for what to do when there is an error retrieving data
}
]]>
</mx:Script>
<!-- HTTPService object defining where to get data from and what to do with it when it is returned.
The actual call to the server is made when the Application is initialized; see the Application tag's
initialize event. -->
<mx:HTTPService id="employeeService"
url="data/employees.xml"
result="resultHandler(event)"
fault="faultHandler(event)"/>
<!-- DataGrid displaying all the data returned from the call to the server -->
<mx:DataGrid dataProvider="{employeeData}"
width="100%" height="100%" />
</mx:Application>
数据employees.xml
本文例子来源:一周学会flex里的FlexInAWeek_Day1_Projects\Video10_Retrieving_Data_via_HTTPService_Solution
原创文章转载请注明出处:云飞扬IT的blog






以后学习flex就来你这里
能再多谢谢关于flex与net sql通信的文章吗??
比如,我在net里面建立dll文件,在flex里面是否可以引用,并调用里面的方法
还是只能在net里面建立webservices,然后在flex里面引用?
期待大幅,谢谢!
好像flex无法引用net的dll文件,除了HTTPService,还可以用webservices交互,目前我也循循渐渐的在学习中,以后学完会多搞些net与flex交互的,毕竟也是搞net的,不用谢!!欢迎你来到我的小站!!