Search code examples
actionscript-3apache-flexremoteobject

flex - reinvoking Operation after faultevent


After invoking a RemoteObject, we sometimes need to reinvoke the same operation until it succeeds.

private var myserviceRO:RemoteObject = new RemoteObject("myService");
[...]
myserviceRO.operationName.addEventListener(ResultEvent.RESULT, myResultHandler);
myserviceRO.operationName.addEventListener(FaultEvent.FAULT, myFaultHandler);
myserviceRO.operationName(arg1, arg2, arg3);
[...]

 protected function myFaultHandler(faultEvent:FaultEvent):void {
        //under some condition, resend the operation that failed
        (faultEvent.currentTarget as Operation).send();

        //under some condition, resend the operation that failed
        (faultEvent.currentTarget as Operation).send((faultEvent.currentTarget as Operation).arguments);
 }

Now as my operation requires 3 arguments, and i have no idea how to pass the parameters to the send() method:

  • when i call send(), i get an error : "0 argument passed, 3 expected"
  • when i call send(operation.arguments), i get "1 argument passed, 3 expected"

The send() documentation specifies that :

  • Executes the method. Any arguments passed in are passed along as part of
  • the method call. If there are no arguments passed, the arguments object
  • is used as the source of parameters.

So if i don't send any arguments, the original arguments are supposed to be used, but apparently the aren't.

Debugging my application shows that (faultEvent.currentTarget as Operation).argumentNames is allways an empty array, and arguments is allways an empty Object.

Can you please tell me how to pass the parameters ?

thank you.


Solution

  • Here's the solution:

    protected function myFaultHandler(faultEvent:FaultEvent):void {
        //Parameters should be set beforehand from the async token
        ((Operation)faultEvent.currentTarget).arguments = faultEvent.token.message.body;
    
        //Now the parameters are ok
        ((Operation)faultEvent.currentTarget).send();
    
    
     }
    

    Credits to @AmyBlankenship blog: http://flexdiary.blogspot.com/2010/02/debugging-responder-result-functions.html