1 Reply Latest reply on Mar 18, 2010 8:59 PM by Radhakrishna Bhat

    Accessing/looping through remote data

    amandamartino

      Hi,

       

      I have a ColdFusion service I'm calling to return a custom data type (the CF service is retuning the data as a query). I can get the data back, bind it to a datagrid, list, etc. with no problems whatsoever. However, I haven't yet figured out how I can loop through that data to do custom processing based on where in the data I am. I'm getting a query back where each record contains an event code, title, open date and close date. Then, for each record in the query, what I'm looking to do is pass in the event code for my current record and return the information associated with that event. My problem is that I haven't been able to loop through the CallResponder returned to get at each individual code in the query. I've been trying different variations of:

       

      [Bindable]

      private var tempString:String = "";

       

      protected function textArea_creationCompleteHandler(event:FlexEvent):void

      {

      getOpenEventsForDisplayResult.token = registrationAPI.getOpenEventsForDisplay();

       

      for(var i:int = 0; i < getOpenEventsForDisplayResult.lastResult.length; i++)

      {

      tempString += "responder: " + getOpenEventsForDisplayResult.lastResult[i].EventCode + " " + getOpenEventsForDisplayResult.lastResult[i].EventCode;

      tempString += "\n";

      }

       

      }

       

      <s:TextArea x="579" y="53" creationComplete="textArea_creationCompleteHandler(event)" text="{tempString}" id="testTextArea" />

       

      Unfortunately this code isn't appending anything to tempString...my text box is empty in this example. I've also tried setting tempString = getOpenEventsForDisplayResult.lastResult.length (right after the getOpenEventsForDisplay() method call), and then I get a runtime error on that line saying "a term is undefined or has no properties." However, if I directly bind the text area's text field to getOpenEventsForDisplayResult.lastResult.length (e.g. <s:TextArea x="579" y="53" creationComplete="textArea_creationCompleteHandler(event)" text="{getOpenEventsForDisplayResult.lastResult.length}" id="testTextArea" />, I get the correct length appearing in the text box. I can also get at each individual array element if I bind lastResult[i] to the textArea's text field. For example, <s:TextArea x="579" y="53" creationComplete="textArea_creationCompleteHandler(event)" text="{getOpenEventsForDisplayResult.lastResult.[2].EventCode}" id="testTextArea" /> works just fine and gives me the correct code at position 3 in the array. Unfortunately, in addition to the obvious reasons why that's not a good solution, I can't do it anyway since I don't know in advance how many records are being returned by my function.

       

      I have a feeling this is probably something glaringly obvious that I'm missing, but it's been driving me nuts for awhile and I would appreciate any guidance anyone can give me.

       

      Thanks in advance!

       

      ~ Amanda

        • 1. Re: Accessing/looping through remote data
          Radhakrishna Bhat Level 3

          Since this is an asynchronous call, You need to wait for ResultEvent of CallResponder.

           

          private var tempString:String = "";

           

           

          protected function textArea_creationCompleteHandler(event:FlexEvent):void

          {

               getOpenEventsForDisplayResult.token = registrationAPI.getOpenEventsForDisplay();

           

               getOpenEventsForDisplayResult.addEventListener(ResultEvent.RESULT,waitForResult);

           

          }

           

          public function waitForResult(event:ResultEvent):void {

           

               for(var i:int = 0; i < getOpenEventsForDisplayResult.lastResult.length; i++)

               {

                    tempString += "responder: " + getOpenEventsForDisplayResult.lastResult[i].EventCode + " " + getOpenEventsForDisplayResult.lastResult[i].EventCode;

                    tempString += "\n";

               }

             

          }

           

           

          <s:TextArea x="579" y="53" creationComplete="textArea_creationCompleteHandler(event)" text="" id="testTextArea" />

           

           

          -Radhakrishna