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?
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>