I have a situation where a single remoteobject call is triggering
multiple faults. In my fault handler, I want to cancel the operation
on the first one. However, I'm not sure how to get from the token to
the operation that was called.
Here's my code:
package com.rw.adBlankenship.remoting
{
import com.rw.adBlankenship.vo.GraphicProfile;
import flash.events.Event;
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
import mx.messaging.Channel;
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.rpc.AsyncToken;
import mx.rpc.Responder;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
public class GetProfiles
{
//-------> shared variables:
//remote object to use:
private static var _ro:RemoteObject=new RemoteObject
();
private static var
_channels:ChannelSet=defaultChannelSet();
/**
* Set the profiles collection to the ArrayCollection
that
* is being used to page through the graphic profiles.
* More profiles will be added to it as they are
loaded
*/
public static var profiles:ArrayCollection = new
ArrayCollection();
//ensures GraphicProfile gets compiled into this class
private static var dummy:GraphicProfile;
//sets up default channel set
private static function defaultChannelSet():ChannelSet
{
/* Once we know the settings logic
works, this will return a
channelset with a default channel
that can be used if none
is specified. */
return new ChannelSet;
}
//allows the endpoint to be set from anywhere in the
application
public static function set endpoint
(gateway:String):void {
var channel:AMFChannel;
//look to see if the channel is already there
for (var i:int=0;
i<_channels.channels.length; i++){
channel=_channels.channels[i];
if (channel.endpoint==gateway) return;
}
//add channel
channel = new AMFChannel('gpChannel'+i,
gateway);
_channels.addChannel(channel);
}
public static function get endpoint():String{
return Channel(_channels.channels
[_channels.channels.length-1]).endpoint;
}
/**
* Executes the getServices service.
* Takes a parameters "object" with the following
properties.
* @param categoryID:int-Category to display profiles
for (use -1 for string search)
* @param searchString:String-Search string to
retrieve profiles for (use null for category search)
* @param page:int-page number of results to retrieve
(defaults to 0)
* @param pageSize:int-size of a "page" of results
(how many to ask for) (defaults to 0)
*/
public static function execute(categoryID:int=-
1,searchString:String=null, page:int=0, pageSize:int=24):void{
if (_channels.channels.length==0) {
throw new Error('No endpoint
specified for GetCategories command Remote Object');
}
_ro.channelSet=_channels;
_ro.destination = 'AMF_Category';
_ro.source = 'AMF_Category';
var token:AsyncToken=_ro.getServices
(categoryID=-1?null:categoryID, searchString, page, pageSize);
token.addResponder(new Responder
(profilesLoaded, profileLoadFailed));
}
/* Populate current ArrayCollection with the
result.
This will generate a CollectionChange
wherever the
other end of the reference is so it will know
the
categories have arrived. */
private static function profilesLoaded
(e:ResultEvent):void{
//keep from sending tons of collection events
profiles.disableAutoUpdate();
for (var i:int=0; i<e.result.length; i++) {
profiles.addItem(e.result[i] as
GraphicProfile);
}
//send the collection event
profiles.enableAutoUpdate();
}
private static function profileLoadFailed
(e:FaultEvent):void{
trace(e.fault);
//dispatch a collection change event so that
the SearchProfiles can react
profiles.dispatchEvent(new CollectionEvent
(CollectionEvent.COLLECTION_CHANGE));
//keep from tying up resources responding to
more faults on this call
var operation:Operation=???;
operation.cancel();
}
}
}
I'd really appreciate it if someone could help me out with what goes
in place of ??? above.
Thanks;
Amy