2 Replies Latest reply on Jan 3, 2007 5:46 AM by 187_2007

    Output CFC query to Flex app

    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. Re: Probably an easy question for you..
          ntsiii Level 3
          First, that is a terrible topic title. Please make your title reflect on the question you are posting, not on your assessment on how difficult it will be for someone else to solve. I don't usually even read topics that I don't think I can help with.

          Now, you techniques look good. So, what do you see if, in your handler function, you do:
          import mx.utils.ObjectUtil
          trace(ObjectUtil.toString(event.result ))

          Tracy
          • 2. Re: Probably an easy question for you..
            187_2007 Level 1
            Ahhh,,, yes, I appologize. I will make better headings next time.. Okay, I tried your solution and it printed out what I wanted and more. SWEET!! Now I think all I need to do is put it in an associated array so I can reference things better. Not sure yet, but I'll play with it. Thanks again... Genius! BTW, here is the output when I ran it:

            mx.collections::ArrayCollection)#0
            filterFunction = (null)
            length = 6
            list = (mx.collections::ArrayList)#1
            length = 6
            source = (Array)#2
            [0] (Object)#3
            NAME = "Rob Capilli"
            TYPE = "Male"
            [1] (Object)#4
            NAME = "Meatball"
            TYPE = "Cat"
            [2] (Object)#5
            NAME = "Sanket"
            TYPE = "male"
            [3] (Object)#6
            NAME = "Sarah"
            TYPE = "Female"
            [4] (Object)#7
            NAME = "1"
            TYPE = "1"
            [5] (Object)#8
            NAME = ""
            TYPE = ""
            uid = "21B5BECE-6A2E-6940-9543-E830E43DAAFA"
            sort = (null)
            source = (Array)#2