InlineInvoker

(This tag must be placed inside an <EventHandlers> tag or a <MessageHandlers> tag)

InlineInvoker allows you to call a method without having to instantiate an object (compare with MethodInvoker). You only need to provide a method to call, which can be a method created in the event map (within a Script block), a static method on a class, or method provided by an already created object or singleton.

Any value returned by the function will be available in the lastReturn. See Using lastReturn and Using Smart Objects (lastReturn)

Example:

<InlineInvoker
   method="methodToExecute"
   arguments="{['argument1', 'argument2']}"/>

Attributes

method

required

The method attribute specifies what function to call. If you had a function called doWork(), you would then write:

<InlineInvoker method="doWork" />

arguments

If the function in your class has arguments, you can pass them via the "arguments" attribute. Suppose your doWork function has the following signature:

public function doWork(name:String, value:Number)

then you can pass those arguments as follows:

<InlineInvoker
   method="doWork"
   arguments="{['Tom', 36]}"/>

Note that the arguments attribute expects an array. See MethodInvoker (arguments section) for more information.

Calling a static method

With the InlineInvoker tag, you can call static methods. For example, you could call the function random() of the Math library:

<InlineInvoker method="Math.random" />

Remember that any value returned by the function will be available in the lastReturn (Using lastReturn).

Calling a local method

If you have created a method in your event map, you can call it with the InlineInvoker tag:

<mx:Script>
private function myMethod():void {
   trace('you called me!');
}
]]>
</mx:Script>

<EventHandlers type="myEventType">
   <InlineInvoker method="myMethod" />
</EventHandlers>

Calling a method on a singleton class

Suppose you have a singleton class that contains the method "myMethod" and that you access the singleton instance by the getInstance() method. Then you could call your the method by:

<InlineInvoker method="{MySingleton.getInstance().myMethod}" />

11 responses so far

  1. hi,

    how can i indicate on which object should be invoked?
  2. That object will have to be accessible in the event map, so that you can call it by:
    <code>
    <InlineInvoker method="{myObject.myMethod}" />
    </code>
  3. You may encounter method not found if your view takes a little longer to load than the map(* when using<InlineInvoker method="{MySingleton.getInstance().myMethod}" />)

    To alleviate, instantiate your map after view has loaded (*creationComplete)
    private function init(){
    var myMap:MainEventMap = new MainEventMap ();
    }
  4. Thank you, Robert Colvin! I spent one hour trying to find the reason of "method not found" bug. This should be added to the project's documentation.
  5. Hi Robert and Roman,
    We are not able to reproduce that. Please post a more extensive example in the forums. As a general rule, however, you don't add even maps to views...
  6. Laura, I thought that's exactly where EventMaps were placed when creating a Document Based type application?
  7. Looks like the new version may have corrected this issue. Also make sure only setters are mapped, via injectors, to view.

Leave a response

If you need help or want to comment on something not related to this page, please post in the forums. Thanks!

Leave this field empty