I have several remote object methods that I want to respond to differently depending on the context, but I would prefer not to create a bunch of different RemoteObject aliases. Any advice on this? Some prerequisites:
Let's say I have an admin application that displays sales statistics in different ways. The remote method is as follows:
<mx:RemoteObject id="rpt" destination="AMFServer"> <mx:method name="getSalesStats" fault="getSalesStatsFault(event)" result = "getSalesStatsSuccess(event)" /> </mx:RemoteObject>
The getSalesStats method takes an employee identifier and a sales type as arguments. You would call it that:
rpt.getSalesStats(120, "peanuts"); public function getSalesStatsSuccess(e:ResultEvent):void { salesdata:ArrayCollection = e.result.rows as ArrayCollection; salesGraph.dataProvider = salesdata; salesGraphPanel.title = "Peanut Sales, 1990"; }
I want to be able to call this method in different contexts, sometimes sending the result to a chart, and sometimes to a datagrid; I want to be able to change the name and type of chart depending on what the user wants. Some of what I want can be achieved by evaluating the data returned from the server; the object contains the name of the report, so I can evaluate this value. But some things need to be changed, based not only on what I will return from the server. If it was a synchronous call, it would be easy; I would do something like:
function buttonOneClick():void { myData1:ArrayCollection = getSalesStats(120, "peanuts"); myChart.dataProvider = myData1; } function buttonTwoClick():void { myData2:ArrayCollection = getSalesStats(120, "cashews"); myDataGrid.dataProvider = myData2; }
I would like to pass something through a remote method to the response function, for example:
rpt.getSalesStats(120, "peanuts", "clicked button one");
but this, of course, causes an error because the server does not want this last argument. Any thoughts? I will clarify if this is confusing.