2 Replies Latest reply on May 29, 2009 5:00 PM by Michael Borbor

    Processing RemoteObject data Step by Step

    ProjectedSurplus Level 1

      My <mx:RemoteObject> hits a CF8 cfc and I can bind to the results using    text="{svcColdFusion.GetHello.lastResult}"

       

      I thought I read in liveDocs that RO's return ArrayCollections by default -- is this correct and/or does the cfc's     returntype="   " affect this?

       

      Or if this is incorrect, then I assume I must cast the RO resultEvent to an array collection?

        • 1. Re: Processing RemoteObject data Step by Step
          ProjectedSurplus Level 1

          From all examples thus far it seems as though the RemoteObject resultEvent must be cast to an ArrayCollection.  Not sure if this can be done in an <mx:ArrayCollection> (comments welcome) rather than in a script block but this works: (for anyone following along my learning path)

          -------------------------------------

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" initialize="svcColdFusion.NewVisitor()">

           

              <mx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                      import mx.rpc.events.ResultEvent;
                      import mx.controls.Alert;
                      import mx.rpc.events.FaultEvent;
                     
                      [Bindable]
                      private var myArray:ArrayCollection

           

                      private function if_RO_Fault(event:FaultEvent):void {
                          mx.controls.Alert.show(event.message as String, "Service Error");
                      }

           

                      private function if_RO_Result(event:ResultEvent):void {
                          myArray = event.result as ArrayCollection;
                      }

           

                  ]]>
              </mx:Script>

           

             
              <mx:RemoteObject id="svcColdFusion"     
                  destination="ColdFusion"      
                  endpoint="http://___your IP num____::8500/flex2gateway/"
                  source="test.cfcs.helloworld" >
                      <mx:method name="SingleRow" fault="if_RO_Fault(event)"
          result="if_RO_Result(event)"/>

           

              </mx:RemoteObject>
             
          <mx:VBox>

           

              <mx:DataGrid id="DG1" dataProvider="{myArray}" />  
                <mx:Label id="Lbl1" text="{myArray.getItemAt(0).familyName}" />
           
          </mx:VBox>
             
          </mx:Canvas>

           

          ----------------------------------------------------

           

           

          Now for the tricky part (IMHO). Correct me if I am wrong, but to separate View from Model, best practice is to NOT directly use the specific elements {myArray.getItemAt(0).familyName} as above but rather to convert them to a Value Object then use that VO to populate attributes.?????

          • 2. Re: Processing RemoteObject data Step by Step
            Michael Borbor Level 4

            Well in that case what you could do is myVOEntity=myVOEntity(myArrayCollection.getItemAt(0))