dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Dynamic function calls?????????

  1. #1
    Member
    Join Date
    Dec 2002
    Posts
    33

    Dynamic function calls?????????

    Hi.
    I am trying to call a 2 different functions from 1 line of code.
    I have seen a few posts on this, but cannot get any of them to work.

    What I am trying to do is:

    I have 2 fuctions. 1 called "func1" and 1 called "func2".

    I am trying to call either one of them with this line:

    eval("func" + Block + "()");

    Where 'Block' is a variable that contains either 1 or 2.

    I can't get this to work. Can you help???

    Thanks in advance.
    Damian.

  2. #2
    Senior Member
    Join Date
    Aug 2001
    Location
    Egypt
    Posts
    332
    Code:
    this["func"+Block]();
    Regards,
    Hamza.

  3. #3
    Member
    Join Date
    Dec 2002
    Posts
    33
    Thanks.
    Worked a treat.

  4. #4
    Junior Member
    Join Date
    Feb 2003
    Posts
    6
    how do u send multiple parameters when calling a function this way, whenever I try to put an array in the brackets, it takes the array as the only parameter rather than multiple parameters

  5. #5
    Senior Member
    Join Date
    Aug 2001
    Location
    Egypt
    Posts
    332
    Hi,
    you have to put all the parameters between parentheses:

    Code:
    function func1(a,b,c) {
      trace("a: " + a);
      trace("b: " + b);
      trace("c: " + c);
    }
    
    var Block = 1;
    this["func"+Block]("myparam1","myparam2","myparam3");
    
    // outputs:
    // a: myparam1
    // b: myparam2
    // c: myparam3
    Hope this helps.
    Cheers.
    Hamza.

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