[font=Arial]I’d like to be able to call a function dynamically, ideas?
I saw an example. It doesn’t work, but perhaps it’s a starting point:
myFunctionName = “myFunction”;
_rootmyFunctionName; [/font]
[font=Arial][/font]
[font=Arial]Thanks, Mike[/font]
That above code works fine for me, you just gotta make sure you define the myFunction function.
function myFunction(args) {
trace(args);
}
myFunctionName = "myFunction";
_root[myFunctionName]("this is an argument");
Unless this changed for 2k4.
Got it. The original code would work, I had a further complication: I was setting myFunctionName to equal “myClass.myFunction” since I need to dynamically reach a function nested within an instance of a class (is that the right way to say that?). Here’s what works for my senario:
function myFunction(args) {
trace(args);
}
myClassName = “myClass”;
myFunctionName = “myFunction”;
_root[myClass][myFunctionName](“this is an argument”);
Thanks.
Yep, that is the correct syntax.
However, that is going by if you class is dynamic as well… otherwise you can change
_root[myClass][myFunctionName]("this is an argument");
to
_root.myClass[myFunctionName]("this is an argument");
and remove the
myClassName = "myClass";
Yep, the class is dynamic, too! Only one level deep tho… so far…
Thanks again.