mx.rpc

# CallResponder - AS3 Flex

Package | mx.rpc
Class | public class CallResponder
Inheritance | CallResponder EventDispatcher Object
Implements | IResponder

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

This component helps you manage the results for asynchronous calls made from RPC based services, typically from MXML components. While each individual service and operation dispatches result and fault events, it is common to need to use the same operation in different parts of your application. Using one event listener or lastResult value across the entire application can be awkward. Rather than creating two service components which refer to the same service, you can use a simple lightweight CallResponder to manage the event listeners and lastResult value for a specific invocation of a service.

You set the token property of this component to the AsyncToken returned by the service. You can then add event listeners on this component instead of having to add them to each AsyncToken returned. This component also maintains the lastResult property which is a copy of the value returned by the last successful result event dispatched by a token monitored by this service. Though you can bind to either the `callResponder.token.result` or `callResponder.lastResult`, the latter will be preserved while a second call to the same service is in progress while the former will be reset as soon as a new service invocation is started.

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | lastResult : * This property stores the result property of the token each time it delivers a successful result. | CallResponder
|  | token : mx.rpc:AsyncToken Each CallResponder dispatches result and fault events received from a single token. | CallResponder

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | EventDispatcher
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | fault(data:Object):void This method is called by the AsyncToken when it wants to deliver a FaultEvent to the CallResponder. | CallResponder
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | result(data:Object):void This method is called by the AsyncToken when it wants to deliver a ResultEvent to the CallResponder. | CallResponder
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher
|  | fault | Dispatched when an Operation call fails. | CallResponder
|  | result | Dispatched when an Operation invocation successfully returns. | CallResponder

Property Detail

### lastResult

property

`lastResult:*`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

This property stores the result property of the token each time it delivers a successful result. You can bind to or access this property instead of the token.result property to keep your code from seeing that value cleared out on the second and subsequent call to a particular service method. Additionally, if a fault occurs this value will still be set to the last successful result returned by a token monitored by this CallResponder.

This property can be used as the source for data binding. When this property is modified, it dispatches the `propertyChange` event.

Implementation
`public function get lastResult():*`
`public function set lastResult(value:any):void`

### token

property

`token:mx.rpc:AsyncToken`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Each CallResponder dispatches result and fault events received from a single token. This property value specifies that token. You typically set this property to the AsyncToken object returned by the service.

This property can be used as the source for data binding. When this property is modified, it dispatches the `propertyChange` event.

Implementation
`public function get token():mx.rpc:AsyncToken`
`public function set token(value:mx.rpc:AsyncToken):void`
Method Detail

### fault

()
method

`public function fault(data:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

This method is called by the AsyncToken when it wants to deliver a `FaultEvent` to the CallResponder. You do not call this method directly.

Parameters

| `data:Object` — The FaultEvent delivered by the AsyncToken

### result

()
method

`public function result(data:Object):void`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

This method is called by the AsyncToken when it wants to deliver a `ResultEvent` to the CallResponder. You do not call this method directly.

Parameters

| `data:Object` — The ResultEvent delivered by the AsyncToken

Event Detail

### fault

Event

Event Object Type: `mx.rpc.events.FaultEvent`
property FaultEvent.type = `mx.rpc.events.FaultEvent.FAULT`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Dispatched when an Operation call fails.

The FAULT event type.

The properties of the event object have the following values:

Property | Value
--- | ---
`bubbles` | false
`cancelable` | true, calling preventDefault() from the associated token's responder.fault method will prevent the service or operation from dispatching this event
`currentTarget` | The Object that defines the event listener that handles the event. For example, if you use `myButton.addEventListener()` to register an event listener, myButton is the value of the `currentTarget`.
`fault` | The Fault object that contains the details of what caused this event.
`message` | The Message associated with this event.
`target` | The Object that dispatched the event; it is not always the Object listening for the event. Use the `currentTarget` property to always access the Object listening for the event.
`token` | The token that represents the call to the method. Used in the asynchronous completion token pattern.

### result

Event

Event Object Type: `mx.rpc.events.ResultEvent`
property ResultEvent.type = `mx.rpc.events.ResultEvent.RESULT`

Language Version: | ActionScript 3.0

Product Version: | Flex 3

Runtime Versions: | Flash Player 9, AIR 1.1

Dispatched when an Operation invocation successfully returns.

The RESULT event type.

The properties of the event object have the following values:

Property | Value
--- | ---
`bubbles` | false
`cancelable` | true, preventDefault() from the associated token's responder.result method will prevent the service or operation from dispatching this event
`currentTarget` | The Object that defines the event listener that handles the event. For example, if you use `myButton.addEventListener()` to register an event listener, myButton is the value of the `currentTarget`.
`message` | The Message associated with this event.
`target` | The Object that dispatched the event; it is not always the Object listening for the event. Use the `currentTarget` property to always access the Object listening for the event.
`result` | Result that the RPC call returns.
`token` | The token that represents the indiviudal call to the method. Used in the asynchronous completion token pattern.

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00