Reputation: 13632
I've followed this tutorial to get some Flex code to call Java code hosted on a Tomcat server.
This is how my RemoteObject and the Button to call the remote function is declared:
<mx:RemoteObject id="productService" destination="productJavaService" result="resultHandler(event)" fault="faultHandler(event)"/>
<mx:Button label="Get all Products" click="productService.getAllProducts()" />
These are the definitions of the resultHandler and faultHandler functions:
private function resultHandler(event:ResultEvent):void
{
products = event.result as ArrayCollection;
}
private function faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultString);
}
The obvious problem with this for me is that the resultHandler is associated with the RemoteObject as a whole rather than the individual function. If I add a new function such as "getSingleProduct" then obviously a different resultHandler will need to be used. How do I specify the resultHandler at function level?
Upvotes: 0
Views: 2534
Reputation: 567
Just wanted to add: in case anyone wants to achieve this with actionscript, you can do this with actionscript by adding a Responder to the AsyncToken returned from the service call:
var responder:Responder = new Responder(onGetOneProductResult, onGetOneProductFault);
var token:AsyncToken = Server.getOneProduct();
token.addResponder(responder);
private function onGetOneProductResult(event:ResultEvent):void {
// event.result is the data you sent back from the server
var result:Object = event.result;
}
private function onGetOneProductFault(event:FaultEvent):void {
trace("onGetOneProductFault : "+event.fault.faultString);
}
Upvotes: 1
Reputation: 13984
You can define a method
property under a RemoteObject
, in your case, it would be getAllProducts()
; You can do so like this:
<mx:RemoteObject id="Server" destination="ServerDestination" fault="faultHandler(event)">
<mx:method name="getAllProducts" result="getAllProductsHandler(event)"/>
<mx:method name="getOneProduct" result="getOneProductHandler(event)"/>
</mx:RemoteObject>
Upvotes: 4