How can we dynamically call a function. I have tried below code:
public function checkFunc() : void
{
Alert.show("inside function");
}
public var myfunc:String = "checkFunc";
public var newFunc:Function=Function(myfunc);
newFunc();
But it gives error:
Call to a possibly undefined method
newFunc.
In place of newFunc(), I tried calling it as this[newFunc](), but that throws error:
The this keyword can not be used in
static methods. It can only be used in
instance methods, function closures,
and global code
Any help in calling the function dynamically?
Functions work the same way properties to, you can assign them the same way you assign variables, meaning that all the funky square bracket tricks work for them too.