MethodInvocationCallback awaits the response of a method invocation.
There are two types of responses.
Depending on the client and service used, that are responsible for propagating the methods on this callback, there may be other circumstances on which a specific callback method is invoked.
This interface can either be instantiated directly or implemented by a class. If you instantiate it directly you must overwrite the callback methods you wanna be informed of with anonymous functions.
Note that implementing this interface is much cleaner and less error-prone. It
is thus recommended to implement this interface whenever possible, instead of
overwriting the methods with anonymous functions. Note also that the direct
instantiation of interfaces is not permitted in Flex.
var callback:MethodInvocationCallback = new MethodInvocationCallback();
callback.onReturn = function(returnInfo:MethodInvocationReturnInfo):Void) {
trace("Invoked method successfully: " + returnInfo);
}
callback.onError = function(errorInfo:MethodInvocationErrorInfo):Void {
trace("Error occured when trying to invoke the method: " + errorInfo);
}
Implementing the interface by a class is a much neater way. But sometimes it
adds unnecessary complexity.
class MyCallback implements MethodInvocationCallback {
public function onReturn(returnInfo:MethodInvocationReturnInfo):Void {
trace("Invoked method successfully: " + returnInfo);
}
public function onError(errorInfo:MethodInvocationErrorInfo):Void {
trace("Error occured when trying to invoke the method: " + errorInfo);
}
}
public function onReturn(returnInfo:MethodInvocationReturnInfo):VoidIs executed when the return value of the method invocation arrives.
This indicates that the method was invoked successfully.
returnInfo | contains the return value and some other useful information about the invoked method |
public function onError(errorInfo:MethodInvocationErrorInfo):VoidIs executed when a method invocation fails.
Known issues are:
Remember that not all clients support this functionalities.
errorInfo | contains information about the error and some useful information about the called method |