2 Replies Latest reply on Apr 19, 2007 2:59 PM by Jighead52

    Multiple remoteObject calls Multiple CFC's

    Jighead52
      Hi,

      I can't figure out how to get data from multiple CFCs within the same page using <mx:remoteObject />
      and get both datagrids to display the data at page load. If someone could post example code that would be tremendous.
      I''ve googled and googled but can't find an answer.

      Here's my none working code, however I think I'm close.

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

      <mx:Script>
      <![CDATA[

      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;

      [Bindable] private var emplist:ArrayCollection;
      [Bindable] private var deptlist:ArrayCollection;
      private function dataHandler(event:ResultEvent):void
      {
      emplist = new ArrayCollection(event.result as Array);
      deptlist = new ArrayCollection(event.result as Array);
      }


      ]]>
      </mx:Script>

      <mx:RemoteObject
      destination="ColdFusion"
      id="Employees"
      source="flexprojects.StaffDirectory.cfc.employeesGateway"
      result="dataHandler(event)" showBusyCursor="true"
      />

      <mx:RemoteObject
      destination="ColdFusion"
      id="Departments"
      source="flexprojects.StaffDirectory.cfc.DeparmentsGateway"
      result="dataHandler(event)"
      showBusyCursor="true"
      />

      <mx:DataGrid dataProvider="{emplist}">
      <mx:columns>
      <mx:DataGridColumn dataField="firstname" headerText="First Name" editable="true"/>
      <mx:DataGridColumn dataField="lastname" headerText="Last Name" editable="true" />
      </mx:columns>
      </mx:DataGrid>


      <mx:DataGrid dataProvider="{emplist}" />

      </mx:Application>
      ------------------------------------------------------------------------------------------

      Thanks
      Gerd
        • 1. Re: Multiple remoteObject calls Multiple CFC's
          JamesEisenlohr
          Gerd,

          Try using the creationComplete attribute in the Application tag. Call a function that calls both of your CFCs. ANd try using two separate result handler functions.

          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical"
          creationComplete="init()" >

          <mx:Script>
          <![CDATA[

          import mx.collections.ArrayCollection;
          import mx.rpc.events.ResultEvent;

          [Bindable]
          private var emplist:ArrayCollection;
          [Bindable]
          private var deptlist:ArrayCollection;

          public function init():void {
          Employees.functionNameInCFC();
          Departments.functionNameInCFC();
          }

          private function empDataHandler(event:ResultEvent):void {
          emplist = new ArrayCollection(event.result as Array);
          }

          private function depDataHandler(event:ResultEvent):void {
          deptlist = new ArrayCollection(event.result as Array);
          }
          ]]>
          </mx:Script>

          <mx:RemoteObject
          destination="ColdFusion"
          id="Employees"
          source="flexprojects.StaffDirectory.cfc.employeesGateway"
          result="empDataHandler(event)" showBusyCursor="true"
          />
          <mx:RemoteObject
          destination="ColdFusion"
          id="Departments"
          source="flexprojects.StaffDirectory.cfc.DeparmentsGateway"
          result="depDataHandler(event)"
          showBusyCursor="true"
          />


          <mx:DataGrid id="empDG" dataProvider="{emplist}" />
          <mx:DataGrid id="depDG" dataProvider="{deptlist}" />

          </mx:Application>

          Hope this helps!

          James
          • 2. Re: Multiple remoteObject calls Multiple CFC's
            Jighead52 Level 1
            SWEET!

            The init function did the trick ... 2 birds 1 stone.. solved both issues with 1 function call.

            James you did your good deed for the day. I'm sure others new to flex will benefit from this answer.

            Big Kudos!
            Gerd