View comments | RSS feed

mx.rpc
Class RelayResponder


All Implemented Interfaces
mx.rpc.Responder

class RelayResponder
extends Object

5/13/2008: Added sentence regarding how to handle result and fault handling methods in another class.
The RelayResponder provides a mechanism for relaying result and fault events to handler methods on an object. If the result and fault handling methods are in the same class that calls the service method, you can indicate that by setting the responder parameter to the identifier this. If they are not in the same class, the responder parameter is a static method of another class that you must previously import into this class. You can name the result and fault handling methods whatever you like but it is a good practice to assign method names that associate them with the service function that you called. For example, if you access a service function called empNames(), you should name the result handling and fault handling methods something like empNames_Result() and empNames_Fault(). For more information on handling results and fault conditions, see Handling service results and errors.



Constructors
RelayResponder ( responder, resultFunc, faultFunc)
Constructs an instance of the RelayResponder object. When you create a Service object, or when you call a specific service function, you can specify the RelayResponder object that contains your result handler and fault handler methods. Note: Do not specify a result handler or fault handler when you create a Service object and when you call a service function. Specifying a result handler or fault handler in both places can cause errors in your application that could be difficult to diagnose. If the result and fault handling methods are in the same class that calls the service method, you can indicate that by setting the responder parameter to the identifier this. You can name the result and fault handling methods whatever you like but it is a good practice to assign method names that associate them with the service function that you called. For example, if you access a service function called empNames(), you should name the result handling and fault handling methods something like empNames_Result() and empNames_Fault(). For more information on handling results and fault conditions, see Handling service results and errors.


Constructor Detail

RelayResponder

RelayResponder( responder, resultFunc, faultFunc)

Constructs an instance of the RelayResponder object. When you create a Service object, or when you call a specific service function, you can specify the RelayResponder object that contains your result handler and fault handler methods. Note: Do not specify a result handler or fault handler when you create a Service object and when you call a service function. Specifying a result handler or fault handler in both places can cause errors in your application that could be difficult to diagnose. If the result and fault handling methods are in the same class that calls the service method, you can indicate that by setting the responder parameter to the identifier this. You can name the result and fault handling methods whatever you like but it is a good practice to assign method names that associate them with the service function that you called. For example, if you access a service function called empNames(), you should name the result handling and fault handling methods something like empNames_Result() and empNames_Fault(). For more information on handling results and fault conditions, see Handling service results and errors.

Parameters
    responder: Object - The object that receives the fault or result calls.
    resultFunc: String - A string that specifies the name of the function to which the result of the service function call should be directed.
    faultFunc: String - A string that specifies the name of the function to which a fault condition should be directed.

Example
The following example creates a RelayResponder object for a call to a specific service function, custService.getCategories(), and assigns it to the responder property of the PendingCall object, pc. The RelayResponder constructor specifies that the result should be returned to the OnCategoryData() method and a fault should be returned to the onCategoryFault() method. It also specifies that these methods are part of current class object (this).
   import mx.remoting.Service;
   import mx.services.Log;
   import mx.rpc.RelayResponder;
   import mx.rpc.FaultEvent;
   import mx.rpc.ResultEvent;
   import mx.remoting.PendingCall;
   import mx.remoting.RecordSet;
   
   // connect to the customer customerData service and call getCategories() method
   // Then establish result and fault handlers, onCategoryData and
   // onCategoryFault for return call
   custService = new Service("http://localhost:8300/flashservices/gateway",
       null,
       "customerData",
       null,
       null);
   var pc:PendingCall = custService.getCategories(); // get all categories
   pc.responder = new RelayResponder(this, "onCategoryData", "onCategoryFault" ); 
   // 
   // result handler method binds category data to combobox, creates event
   // listener to update combobox when category data changes, and refreshes 
   // associated customer data
   function onCategoryData( re:ResultEvent ):Void {
     mx.remoting.debug.NetDebug.trace({level:"Debug", 
       message:"onCategoryData" });
   // use data glue to remap the fields so that label = name field and 
   // data = id field
     DataGlue.bindFormatStrings( custCat_cmbo, re.result, "#Name#", "#ID#" );
     custCat_cmbo.addEventListener( "change", onCustCat_Change );
     refreshCustomerData();
   }
   // fault handler method displays trace message 
   function onCategoryFault( fault:FaultEvent ):Void {
     // notify the user of the problem
     //
     mx.remoting.debug.NetDebug.trace({level:"None", 
       message:"There was a problem: " + fault.fault.faultstring });
   }
   
The following example creates a RelayResponder object, custSerResp, that will receive control for all results and fault conditions that occur for the custService Service. Results for any call to the service are returned to the onCategoryData() method and any errors are returned to the onCategoryFault() method.
   var custSerResp:RelayResponder = new RelayResponder(this, "onCategoryData", "onCategoryFault");
   custService = new Service("http://localhost:8300/flashservices/gateway",
       null,
       "customerData",
       null,
       custSerResp);
   
You can also create the RelayResponder in the Service constructor as follows:
   custService = new Service("http://localhost:8300/flashservices/gateway",
       null,
       "customerData",
       null,
       new RelayResponder(this, "onCategoryData", "onCategoryFault"));
   

Comments


No screen name said on Mar 29, 2005 at 1:49 PM :
I got error :
There is no class or package with the name 'mx.rpc.RelayResponder' found in package 'mx.rpc'.

I have macromedia flash MX v7.2 and Flash remoting component installed,what else can I do to get this resolved?
No screen name said on Jul 12, 2005 at 10:06 AM :
you need to make sure you have the either the RemotingConnector or the RemotingClasses in the Library of the .fla you are compiling. You will always see that error if you are checking the syntax of the class, not to worry, it works so long as the right items are in the library.
uadrive said on Sep 21, 2005 at 11:38 AM :
What I did to stop getting this error is go to the publish settings and set flash to use ActionScript 2.0 instead of 1.0. Now, I get no errors checking for

import mx.remoting.NetServices;

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flashremoting/mx2004/actionscript_api_reference/mx/rpc/RelayResponder.html