Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you find yourself doing this often (esp. with more than 2 remote calls), you might want to write your own custom class that handles AsyncTokens from remote calls with a final result() function that is invoked when all remote calls end in success.</p> <p>If not, since ActionScript is single-threaded, you can just use a local variable to track whether both calls have succeeded.</p> <pre><code>private var resultFromRemoteCallA:Object; private var resultFromRemoteCallB:Object; private function handleRemoteCallA(event:ResultEvent):void { resultFromRemoteCallA = event.result; C(); } private function handleRemoteCallB(event:ResultEvent):void { resultFromRemoteCallB = event.result; C(); } private function C():void { if (resultFromRemoteCallA &amp;&amp; resultFromRemoteCallB) { // do some thing with the results. } } private function update():void { resultFromRemoteCallA = resultFromRemoteCallB = null; A(); B(); } </code></pre> <p>If you expect null values, you might want to use a boolean variable to track the invocation of the result handler instead.</p> <p><strong>EDIT</strong>: since the author indicated that the dispatch happens in another class, another way to do it would be to pass along a responder and attach it to the AsyncToken like so (in the callee):</p> <pre><code>private function dispatchRemoteCall(resultHandler:Function, faultHandler: Function): void { var resultToken: AsyncToken = remoteObject.foo('bar'); // remoteObject may or may not have a result/fault handler resultToken.addResponder(new mx.rpc.Responder(resultHandler, faultHandler)); } </code></pre> <p>Then, you can pass along listeners to be invoked when the remote call finishes (at which point you can choose to let the dispatching class store the result or handle it in the caller), like so:</p> <pre><code>private function update(): void { classA.dispatchRemoteCall(handleRemoteCallA, handleRemoteCallAFault); } </code></pre> <p>If you find yourself doing this a lot, you may also want to look into having a framework do global event routing, like Parsley or Spring Actionscript.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload