1 Reply Latest reply on Jan 2, 2007 3:36 PM by phi2265

    Probably an easy question for you..

    187_2007
      I have a CFC which simply calls the DB and returns the results to the Flex app.

      CFC:

      <cfcomponent>

      <cffunction name="runQuery" output="false" access="public" returntype="Query">
      <cfquery name="qry_login" datasource="EWPROJ">
      SELECT *
      FROM ROBERTTEST
      </cfquery>
      <cfreturn qry_login>
      </cffunction>

      </cfcomponent>


      Simple enough.......


      Here is my Flex file...

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp();">


      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

      [Bindable]
      private var qry_result:ArrayCollection;

      private function initApp():void //first thing to load
      {
      callCFC.runQuery()
      }

      private function resultHandler(event:ResultEvent):void
      {
      var qry_result:ArrayCollection = new ArrayCollection(); //New Array Object called p1
      qry_result.source=event.result as Array;

      trace(qry_result);
      }
      ]]>
      </mx:Script>


      <mx:RemoteObject id="callCFC" destination="ColdFusion" source="CFIDE.samples.FlexToCFC.CFC.myCFC"
      result="resultHandler(event)"
      showBusyCursor="true" />

      </mx:Application>


      my problem is within the [resultHandler] I want to simply create a variable that will contain my results of the object I passed so I can trace it to the screen.... I know that the object is returning correctly, by tracing result.event. What am I doing wrong here, cause it shows nothing.

      I'm guessing that my problem is that I am not putting the object into some sort of array or string where I can access it... How do I do this correctly? Thanks everyone.
        • 1. Probably an easy question for you..
          phi2265 Level 1
          i think it could possibly be that the query is running before it actually gets the string it needs to search for.. making it return empty.

          i just had this problem with a URLRequest.. i had it requesting the file before it got the file name(which is passed in from an xml file)

          my solution was to re-order things so that they happened in the right order.

          vars were declared at the top of <![CDATA[ and i have 2 functions, one to run on creationComplete, and the other.. which is the event handler is called before i load the requested file, by doing:
          loader.addEventListener(Event.COMPLETE, completeHandler);

          here is my code if it is of any help, all in <![CDATA[..
          private static const windowsCRLF:RegExp = /\r\n/gm;
          public var textImport:String;
          public var fileName:String;
          public var loader:URLLoader;
          public var request:URLRequest;


          public function firstLoad():void{
          fileName = data.clip;
          loader = new URLLoader();
          request = new URLRequest(fileName);

          loader.addEventListener(Event.COMPLETE, completeHandler);
          loader.load(request);
          }


          public function completeHandler(event:Event):void{
          loader = URLLoader(event.target);
          textImport = new String(loader.data);
          textImport = textImport.replace(windowsCRLF, "\n");
          text1.text = textImport.toString();
          }

          i had "loader.laod(request);" happening before "loader.addEventListener"
          data.clip is information from xml, in this case it is a path leading to a text file to be loaded.