dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: can't figure out how to call a function using a variable for its name..

  1. #1
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991

    can't figure out how to call a function using a variable for its name..

    Hi

    basically, i want to call a function from within a function using a variable representing its name...

    eg

    i have 3 functions

    funcA()
    funcB()
    funcC()


    i need to call that from a function....

    runFunction = function(functionName){
    _root.eval(functionName);
    }


    so I'd call it like

    runFunction("funcA()");


    i've been tryin to figure this out for quite some time now since FLASH MX , i just kept abandoning a solution.. and now i'm once again in need of this , still cant solve it so im postin...

    i really hope this is possible.. would save me a lot of work.. hehe

    regards

    TJ

  2. #2
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Ensure your functions are on the root timeline and:

    function runFunction(functionName){
    _root[functionName]();
    }


  3. #3
    Senior Member
    Join Date
    Jun 2003
    Location
    Kent, WA
    Posts
    536
    Addendum to virual's code: Give it the string value for the function name, no parenthesis.

    Code:
    // This won't work
    runFunction("funcA()");
    
    // This will
    runFunction("funcA");

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center