(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}" />
how can i indicate on which object should be invoked?
<code>
<InlineInvoker method="{myObject.myMethod}" />
</code>
Could you be more specific from your last response? I'm mostly following what you said, but am unclear on what you mean by "object will have to be accessible in the event map". Do you mind providing a more detailed example. Thanks.
What if I need to receive a response from the called method? For instance, the method returns a Boolean value?
Thanks and Happy New Year!
In my main I have:
<comp:DTV id="dataTable" ...>
Inside the DTV is a method:
private function export():void {}
In the eventmap I want to have my event handler call the method but it never compiles, here is what we tried:
<Script..
import mx.core.FlexGlobals;
private var dtv:DataTableView = FlexGlobals.topLevelApplication.DataTableView;
<EventHandlers ...
<InlineInvoker method {dtv.exportTableToDisk}"...
Can someone give us an answer?
First I did a typo and the function is exportTableToDisk not export and if I make it public not private, it will compile but the end result is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
on the InlineMethod.
I would recommend you to create a function in your map to make the method call you need and call that method with InlineInvoker.