Using lastReturn

Every tag inside a handlers block generates a "lastReturn" that can be used by the immediately next tag. While most tags do not return any value, you can make your method invokers take advantage of it.

If your function call returns something other than void, that value will be stored in the scope's "lastReturn" value. This value can be used by other tags as they would use the event, the result object or server faults. This value will be null if your function returns void.

For example, say you have a class that calculates shipping costs and you want to send that value along with other things to the server. So your function would look like:

public function calculateShipping(weight:Number):Number {
   //do calculation
   return someNumber;

In your handlers block, you will call your class and then send the information to the server:

<MethodInvoker generator="{MyClass}" method="calculateShipping" arguments="{[event.itemWeight]}" />

<WebServiceInvoker arguments="{[lastReturn, event.itemId]}" .....service attributes....>

Because your method call returned a value, the next tag (the WebServiceInvoker) can use it.

More information at Using Smart Objects (lastReturn).

3 responses

  1. Will a non-null lastReturn value be set for a function that has an indeterminate return:

    public myFunction():*

    that can return any type of object?
  2. Yes, it doesn't matter what the return type is.
  3. how can in got a return value by method from the ModelManager class. when I call the method by methodInvoker in the event map.

    for example:
    In the

    public function hello():int{
    var i:int=0;
    return i;

    how can in got the vale of " i " in view page where i dispach the event. by using the eventMap class using mate tag.

    Manpreet Patil

Comments now closed