0 Replies Latest reply on Feb 15, 2007 10:20 PM by Newsgroup_User

    Trouble adapting web service example from cflex

    Level 7
      Hi Everyone-
      I am trying to get a stock quote web service working based on Tracy Spratt's
      Webservice example at cflex
      ( http://cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&objectID=582).
      Instead of a zip code I would like to enter symbols and then display the
      last price, name, change, etc. I am trying to use the Xignite GetQuotes
      service ( http://preview.xignite.com/xQuotes.asmx?op=GetQuotes) but I am
      running into trouble. It gives me the error:

      TypeError: Error #1009: Cannot access a property or method of a null object
      reference.

      at _xlQuoteData = xmlResultNode.Quote;

      I thought it was going to be pretty simple with just some minor changes and
      substitutions but I am not sure what is going wrong. My code is below and
      in that is some sample output from the xignite service. I would really
      appreciate any help anyone could give. Thanks!
      -Dan






      <?xml version="1.0"?>
      <!-- Simple example to demonstrate the WebService tag. -->
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      creationComplete="initApp()">

      <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;
      import mx.managers.CursorManager;
      import mx.controls.dataGridClasses.DataGridColumn;

      default xml namespace = " http://www.xignite.com";

      [Bindable]
      private var _xmlResult:XML; //holds the result xml
      [Bindable]
      private var _xlQuoteData:XMLList; //dataProvider for the datagrid

      private function getStockQuotes():void {
      CursorManager.setBusyCursor();
      WS.GetQuotes.send();
      }

      /** called by the WebService result event. Sets the dataProviders as
      necessary */
      private function onResult(oEvent:ResultEvent):void {
      _xmlResult = XML(oEvent.result);
      var xmlResultNode:XML = _xmlResult.GetQuotesResult[0];
      //var xmlQuoteNode:XML = xmlResultNode.Quote[0];
      outputInfo.text = _xmlResult.toXMLString();
      //resultNode.text = xmlResultNode.toString();
      //_sName = xmlResultNode.Name.text() + " (" + xmlResultNode.Symbol.text()
      + ")";
      _xlQuoteData = xmlResultNode.Quote;
      CursorManager.removeBusyCursor();
      }

      /* private function onResult(oEvent:ResultEvent):void {
      _xmlResult = XML(oEvent.result);
      var xmlResultNode:XML = _xmlResult.GetWeatherByZipCodeResult[0];
      var xmlDetailsNode:XML = xmlResultNode.Details[0];
      outputInfo.text = _xmlResult.toXMLString();
      _sPlace = xmlResultNode.PlaceName.text() + ", " +
      xmlResultNode.StateCode.text();
      _xlDayData = xmlDetailsNode.WeatherData;
      CursorManager.removeBusyCursor();
      } */

      private function lfQuoteData(oItem:Object, dgc:DataGridColumn):String {
      var sReturn:String = "";
      var xmlItem:XML = XML(oItem); //get the item object case as an xml object
      var sHeaderText:String = dgc.headerText; //get the header text for this
      column
      switch (sHeaderText) //logic to determine which node to get data from
      {
      case "Name":
      sReturn = xmlItem.Name.text();
      break;

      case "Symbol":
      sReturn = xmlItem.Symbol.text();
      break;

      case "Last":
      sReturn = xmlItem.Last.text();
      break;

      case "Change":
      sReturn = xmlItem.Change.text();
      break;

      case "Volume":
      sReturn = xmlItem.Volume.text();
      break;
      }
      return sReturn;
      }

      [Bindable]
      private var xlcDP:XMLListCollection;

      private function initApp():void
      {
      var xmlDP:XML =
      <data>
      <Quote>
      <Outcome>Success</Outcome>
      <Identity>Cookie</Identity>
      <Delay>0.5625</Delay>
      <Name>MICROSOFT CP</Name>
      <Exchange>NASDAQ</Exchange>
      <Symbol>MSFT</Symbol>
      <Previous_Close>29.98</Previous_Close>
      <Open>29.82</Open>
      <High>29.86</High>
      <Low>29.62</Low>
      <Last>29.64</Last>
      <Bid>29.55</Bid>
      <Bid_Size>N/A</Bid_Size>
      <Ask>29.67</Ask>
      <Ask_Size>N/A</Ask_Size>
      <Percent_Change>-1.13</Percent_Change>
      <Change>-0.34</Change>
      <Volume>37974456</Volume>
      <High_52_Weeks>30.26</High_52_Weeks>
      <Low_52_Weeks>21.46</Low_52_Weeks>
      <Date>12/22/2006</Date>
      <Time>4:00:00 PM</Time>
      </Quote>
      <Quote>
      <Outcome>Success</Outcome>
      <Identity>Cookie</Identity>
      <Delay>0.5625</Delay>
      <Name>Intel</Name>
      <Exchange>NASDAQ</Exchange>
      <Symbol>INTC</Symbol>
      <Previous_Close>15.15</Previous_Close>
      <Open>15.00</Open>
      <High>16.00</High>
      <Low>29.62</Low>
      <Last>15.97</Last>
      <Bid>29.55</Bid>
      <Bid_Size>N/A</Bid_Size>
      <Ask>29.67</Ask>
      <Ask_Size>N/A</Ask_Size>
      <Percent_Change>-1.13</Percent_Change>
      <Change>-0.34</Change>
      <Volume>37974456</Volume>
      <High_52_Weeks>30.26</High_52_Weeks>
      <Low_52_Weeks>21.46</Low_52_Weeks>
      <Date>12/22/2006</Date>
      <Time>4:00:00 PM</Time>
      </Quote>
      </data>
      xlcDP = new XMLListCollection(xmlDP.Quote);
      }

      ]]>
      </mx:Script>

      <mx:WebService id="WS" wsdl=" http://www.xignite.com/xQuotes.asmx?WSDL"
      useProxy="false"
      fault="Alert.show(event.fault.faultString), 'Error'"
      result="onResult(event)" >

      <mx:operation name="GetQuotes" resultFormat="e4x" >
      <mx:request>
      <Symbol>{tiSymbols.text}</Symbol>
      </mx:request>
      </mx:operation>
      </mx:WebService>

      <mx:Panel title="Webservice Stock Quotes" height="75%"
      paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"
      id="myPanel">
      <mx:TextArea x="200" width="400" height="250" id="outputInfo" />
      <mx:TextArea x="200" width="400" height="250" id="resultNode" />
      <mx:HBox>
      <mx:Label width="100%" color="blue"
      text="Enter one or more symbols separated by commas or spaces"/>
      <mx:TextInput id="tiSymbols" text="MSFT"/>
      <mx:Button label="Get quotes" click="getStockQuotes()"/>
      </mx:HBox>

      <mx:DataGrid dataProvider="{_xlQuoteData}" height="180">
      <mx:columns>
      <mx:DataGridColumn labelFunction="lfQuoteData" headerText="Name"
      width="200" />
      <mx:DataGridColumn labelFunction="lfQuoteData" headerText="Symbol"
      width="200" />
      <mx:DataGridColumn labelFunction="lfQuoteData" headerText="Last"
      width="200" />
      <mx:DataGridColumn labelFunction="lfQuoteData" headerText="Change"
      width="100" />
      <mx:DataGridColumn labelFunction="lfQuoteData" headerText="Volume"
      width="100" />
      </mx:columns>
      </mx:DataGrid>

      </mx:Panel>


      </mx:Application>