Hello Everyone, I have a basic stock quote webservice that I am trying to use to populate a datagrid. There is a service for retrieving one quote at a time which I got to work fine but when I try to use the one that returns an array of different quotes I am having issues. The output of the webservice (GetQuotes) is:
<GetQuotesResult> <Quote> <Symbol></Symbol> <Name></Name> <Last></Last> </Quote> <Quote> <Symbol></Symbol> <Name></Name> <Last></Last> </Quote> </GetQuotesResult> My code is below - I have just been trying everything I can think of but so far now luck. Any help would be greatly appreciated - I'm sure it is just something small I am missing. Thanks for your help! -Dan <?xml version="1.0"?> <!-- Simple example to demonstrate the WebService tag. --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="WS.GetQuotes.send()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.ResultEvent; import mx.rpc.events.FaultEvent; import mx.rpc.soap.LoadEvent; import mx.rpc.soap.*; import mx.collections.XMLListCollection; default xml namespace = "http://www.xignite.com/"; public function onMyResult(event: ResultEvent) :void { var myObject:Object = Object(event.result); } private function myLabelFunc(item:Object, column:DataGridColumn):String { if (item.Quote.Symbol==undefined) {return null;} else {return item.Quote.Symbol + " " + item.Quote.Last;} } private function returnLast(item:Object, column:DataGridColumn):String { {return item.Last;} } private function returnSymbol(item:Object, column:DataGridColumn):String { {return item.Quote.Symbol;} } [Bindable] private var xlcDP:XMLListCollection; [Bindable] private var _xmlResult:XML; //holds the result xml private function onResult(oEvent:ResultEvent):void { _xmlResult = XML(oEvent.result); var xlcDP:XML = _xmlResult.Quote[0]; outputInfo.text = _xmlResult.toXMLString(); //outputInfo.text = WS.GetQuotes.toString(); } private function initApp():void { WS.GetQuotes.send(); } ]]> </mx:Script> <mx:Model id="localQuotes">{WS.GetQuotesResults}</mx:Model> <mx:Model id="results">{_xmlResult}</mx:Model> <mx:WebService id="WS" wsdl="http://www.xignite.com/xQuotes.asmx?WSDL" useProxy="false" showBusyCursor="true" fault="Alert.show(event.fault.toString(),'Error')" result="onResult(event)"> <mx:operation name="GetQuotes" resultFormat="e4x"> <mx:request> <Symbol>IBM PG</Symbol> </mx:request> </mx:operation> </mx:WebService> <mx:Panel title="WebService Example" height="75%" width="75%" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"> <mx:Label width="100%" color="blue" text="Enter a stock symbol to obtain a quote."/> <mx:TextInput id="stockSymbol" text=""/> <mx:Button label="Get Quote" click="WS.GetQuote.send()"/> <mx:Label text="Company: {WS.GetQuote.lastResult.Name}" fontWeight="bold"/> <mx:Label text="Last Price: {WS.GetQuote.lastResult.Last}" fontWeight="bold"/> <mx:Label text="Quote Last Price: {WS.GetQuote.lastResult.Quote}" fontWeight="bold"/> <mx:Label text="Symbol: {WS.GetQuote.lastResult.Quote.Symbol}"/> <mx:Label text="Last Price: ${WS.GetQuote.lastResult.Quote.Last}"/> <!--<mx:DataGrid id="dgStock" dataProvider="{WS.GetQuote.lastResult}">--> <!-- xlcDP --> <mx:DataGrid id="dgStock" dataProvider="{xlcDP}"> <mx:columns> <mx:Array> <!--<mx:DataGridColumn headerText="Symbol" labelFunction="returnSymbol"/>--> <mx:DataGridColumn headerText="Name" dataField="Name"/> <!--<mx:DataGridColumn headerText="Last Price" labelFunction="returnLast"/>--> <mx:DataGridColumn headerText="Exchange" dataField="Exchange"/> </mx:Array> </mx:columns> </mx:DataGrid> <mx:DataGrid dataProvider="{results}"> <mx:columns> <mx:DataGridColumn headerText="Symbol" dataField="Symbol"/> <mx:DataGridColumn headerText="Name" dataField="Name"/> <mx:DataGridColumn headerText="Last Price" dataField="Last"/> </mx:columns> </mx:DataGrid> <mx:TextArea x="200" width="400" height="250" id="outputInfo" /> </mx:Panel> </mx:Application>