1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundGradientColors="[0x000000,0x323232]" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
[Bindable] private var products:ArrayCollection;
private function resultHandler(event:ResultEvent):void
{
products = event.result.catalog.product;
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultDetail, "Error");
}
]]>
</mx:Script>
<!-- HTTPService calls are asynchronous. The result event is triggered on the HTTPService
when the data becomes available to the client application. The fault event is triggered
if an error occurs at the server-side, or if the network becomes unavailable. -->
<mx:HTTPService id="srv" url="catalog.xml"
result="resultHandler(event)"
fault="faultHandler(event)"/>
<mx:DataGrid dataProvider="{products}" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn dataField="productId" headerText="Product Id"/>
<mx:DataGridColumn dataField="name" headerText="Name"/>
<mx:DataGridColumn dataField="price" headerText="Price" textAlign="right"/>
<mx:DataGridColumn dataField="qtyInStock" headerText="Qty" textAlign="right"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Get Products" click="srv.send()"/>
</mx:Application> |
Partager