Advertisement

07.15.2008 at 02:15AM PDT, ID: 23565425
[x]
Attachment Details

Actionscript Calling a function from a string

Asked by options_strategy in ActionScript, Macromedia Flash

Tags:

Hi All,

I have a class that I'm trying to keep as generic as possible. What i want to do is send it a string on set up that contains the name of a global function (or something similar). At some point during use I will ask the class to call this function. What's the best way to do this?

I was hoping to do something similar to this:

var instance_specific_function = "doThisForThisInstanceOnly()";

eval(instance_specific_function);

but it doesn't appear to work.

After reading a bit online it appears that the eval function is very limited in what it can do.

Is there a better way of doing this sort of thing? eventDispatch??

A bad approach (but perhaps the only one) could be having a generic function that receives the string and then using a whole mass of switch statements I can call the required function. Obviously this isn't very neat and I'd prefer to avoid this if possible.

Any advice, pointers, code snippets would be greatly appreciated.

Btw... I'm using Flash CS3 with actionscript 2.Start Free Trial
[+][-]07.15.2008 at 03:14AM PDT, ID: 22005438

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: ActionScript, Macromedia Flash
Tags: Actionscript
Sign Up Now!
Solution Provided By: aneeshchopra
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.15.2008 at 03:15AM PDT, ID: 22005442

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 05:30PM PDT, ID: 22012337

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.15.2008 at 06:35PM PDT, ID: 22012644

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628