RemoteObject code in Actionscript instead of mxml

actionscript-3apache-flex

There another person asking the same question here:

How do I call a RemoteObject method from ActionScript?

but what I need is to add more than one method to the RemoteObject.

Using the other question's example but adding one more method, how would this look in actionscript?

<mx:RemoteObject id="Server" destination="Server" source="gb.informaticasystems.Server" fault="handler_backendCommunicationFails(event)" >
  <mx:method name="executeQuery" result="handler_fetchDataRequestSuccess(event)"/>
  <mx:method name="getData" result="handler_getDataSuccess(event)"/>
</mx:RemoteObject>

Shua: Thanks a lot. You almost had it, with a couple of changes this is it:

var query:AsyncToken = ro.getQuery();
query.addResponder(new Responder(handler_fetchDataRequestSuccess, handler_fetchDataRequestFault) );

Needs both the result and fault methods in the Responder. And I've added multiple different methods using this.

Best Answer

import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.mxml.RemoteObject;

var ro:RemoteObject = new RemoteObject();
ro.destination = "Server";
ro.source = "gb.informaticasystems.Server";
ro.addEventListener( FaultEvent.FAULT, handler_backendCommunicationFails );


var query:AsyncToken = ro.executeQuery();
query.addResponder(new Responder( handler_fetchDataRequestSuccess ) );

var data:AsyncToken = ro.getData();
data.addResponder(new Responder( handler_getDataSuccess ) );