Note that there are some explanatory texts on larger screens.

plurals
  1. POFlex RemoteObject - handling multiple requests
    text
    copied!<p>I have a couple of remote object methods that I want to respond to in different ways depending on the context, but I'd rather not set up a bunch of different RemoteObject aliases. Any advice on doing that? Some background:</p> <p>Let's say I have an admin application that displays sales stats in different ways. The remote method looks like: </p> <pre><code>&lt;mx:RemoteObject id="rpt" destination="AMFServer"&gt; &lt;mx:method name="getSalesStats" fault="getSalesStatsFault(event)" result = "getSalesStatsSuccess(event)" /&gt; &lt;/mx:RemoteObject&gt; </code></pre> <p>The getSalesStats method takes an employee ID and a sales type as its arguments. You'd call it like: </p> <pre><code>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"; } </code></pre> <p>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 title 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 report name, so I can evaluate that value. But some things need to change based on more than just what I get back from the server. If this was a synchronous call, it would be easy; I'd do something like: </p> <pre><code>function buttonOneClick():void { myData1:ArrayCollection = getSalesStats(120, "peanuts"); myChart.dataProvider = myData1; } function buttonTwoClick():void { myData2:ArrayCollection = getSalesStats(120, "cashews"); myDataGrid.dataProvider = myData2; } </code></pre> <p>I'd like to pass something through the remote method to the responding function, like: </p> <pre><code>rpt.getSalesStats(120, "peanuts", "clicked button one"); </code></pre> <p>but that of course throws an error because the server doesn't want that last argument. Any thoughts? I'll clarify if this is confusing.. </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