1 Reply Latest reply on Jul 16, 2007 7:01 PM by Newsgroup_User

    Using results from multiple cfc functions

    Mark Forsberg Level 1
      I'm using the following code to teach myself flash/flex. My question is, how do I differentiate how to handle the various results from a CFC?

      This function sees both calls as the same result. How can I handle each separately?

      private function remotingCFCHandler(e:ResultEvent):void
      {
      returnedText.text = ObjectUtil.toString(e.result);
      }

      CODE:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:RemoteObject
      id="myCfc"
      destination="ColdFusion"
      source="test.components.User"
      result="remotingCFCHandler(event)"/>

      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.utils.ObjectUtil;

      private function remotingCFCHandler(e:ResultEvent):void
      {
      returnedText.text = ObjectUtil.toString(e.result);
      }

      private function callRemotingCFC():void
      {
      // invoke sayHelloString method on User.cfc
      myCfc.sayHelloString();
      }

      private function myCFCTest():void{
      myCfc.myCFCTest();
      }

      private function clearText():void{
      returnedText.text = '';
      }
      ]]>
      </mx:Script>
      <mx:VBox>
      <mx:TextArea id="returnedText" />
      <mx:HBox>
      <mx:Button label="Show" click="callRemotingCFC()"/>
      <mx:Button label="Clear" click="clearText()" />
      </mx:HBox>


      <mx:HBox>
      <mx:Text x="10" y="80" text="Not Yet" id="myTextBox"/>
      <mx:Button label="Mine" click="myCFCTest()" />
      </mx:HBox>
      </mx:VBox>
      </mx:Application>

      Thanks for the assist. This is pretty awesome stuff.

      Mark F
        • 1. Re: Using results from multiple cfc functions
          Level 7
          Hi Mark,

          In addition to providing service level responders, you can also provide operation-level
          responders and even invocation-level responders. I've shown a snippet below
          for registering invocation-level responders on the mx.rpc.AsyncToken that
          is returned from a method call on a RemoteObject...

          import mx.rpc.events.FaultEvent;
          import mx.rpc.events.ResultEvent;
          import mx.rpc.AsyncResponder;
          import mx.rpc.AsyncToken;

          private function callRemotingCFC():void
          {
          // invoke sayHelloString method on User.cfc
          var token:AsyncToken = myCfc.sayHelloString();
          var responder:AsyncResponder = new AsyncResponder(handleSpecificResult,
          handleSpecificFault);
          token.addResponder(responder);
          }

          private function handleSpecificResult(event:ResultEvent):void
          {
          // Handle result.
          }

          private function handleSpecificFault(event:FaultEvent):void
          {
          // Handle fault.
          }


          Another approach entirely involves getting the AsyncToken from a result or
          fault event's token property as this will be the same AsyncToken that was
          immediately returned on invoking a method on a RemoteObject. You simply decorate
          the token with some identifier and then use that when processing the async
          event.

          private function callRemotingCFC():void
          {
          // invoke sayHelloString method on User.cfc
          var token:AsyncToken = myCfc.sayHelloString();
          token.opLabel= "sayHello1";
          }

          private function handleResult(event:ResultEvent):void
          {
          var token:AsyncToken = event.token;
          if (token.opLabel == "sayHello1")
          {
          // ... handle this specific result
          }
          else
          {
          // ...
          }

          }

          // etc...