4 Replies Latest reply on Jun 22, 2006 8:38 AM by ntsiii

    How to get data in Flex 2 Beta 3

    Level 7
      Has anyone worked out an easy way to get data into AS3?

      Say I have a cfc called dataCFC with a method called get which returns a
      query object.

      How can I get this data into a dataProvider in AS3?

      I can't say I'm very keen to use Flex Data Services to do it
      http://labs.adobe.com/wiki/index.php/Flex_Enterprise_Services:overview#Flex_Data_Managemen t_Service
      as it seems to me that this fails at point 4:

      "Finally, if a conflict is detected when applying changes at the
      server-side, an exception is thrown at the client-side, and you can use
      a sophisticated conflict resolution API to handle the conflict

      First of all I can't see how the service could truly tell whether there
      is a conflict if it depends on the status of data in several tables and
      secondly I suspect that AS code to "handle the conflict" would be much
      more difficult to write than doing it in CF which even when the conflict
      test is complex is actually very simple to write.

        • 1. Re: How to get data in Flex 2 Beta 3
          ntsiii Level 3
          By far the simplest way to get data into Flex is using HTTPService.

          Where does your data reside?

          • 2. Re: How to get data in Flex 2 Beta 3
            ntsiii Level 3
            Oops, I see, CF. I do not know CF but I am sure you can use HTTP service with it. Search here, google, I am sure you will find some more CF specific info.
            • 3. Re: How to get data in Flex 2 Beta 3
              Level 7
              Thanks so much, you put me on the right track and finally I've got it to
              work. It's neat and simple unlike all that horrible muddle and mess in
              Flex Data Services.

              It turns out that using Remote Object is easier than HTTP Service,
              although basically it's the same.

              The following code calls a CFC and puts the results in a datagrid:

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*"

              import mx.rpc.events.*;

              public var res:Object = {};

              private function initApp():void
              svc.methodName()//where methodName is the name of the function
              in myCFC

              public function resultHandler(event:ResultEvent):void
              res = event.result;//expects a cf query object

              <mx:RemoteObject id="svc" destination="ColdFusion"
              source="myDir.myCFC"//where myCFC is the name of the cfc file
              (omitting .cfc) and myDir is the path to the cfc under wwwroot
              showBusyCursor="true" />

              <mx:Panel width="450" height="400" layout="absolute" title="Main
              Application Window">
              <mx:DataGrid id="dg" dataProvider="{res}" editable="true">
              <mx:DataGridColumn dataField="colName" headerText="Column Name"
              editable="false"/>//and so on for each column in the query


              • 4. Re: How to get data in Flex 2 Beta 3
                ntsiii Level 3
                Excellent. I don't do CF at all, or very much Java, so I didn't tink to suggest RemoteObject, but it is a very good way to get data. While there is some debate on the subject, RemoteObject is often considered the fastest of the three "RPC" protocols, with WebService being the slowest.

                Your example is great, it will surely help others.