A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Dynamic Function Calls...possible??

  1. #1
    Junior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    24
    Is it possible to dynamically call a function..1 of 2 functions in the pTest object:


    Such as...

    //=================
    // functions are: myFunction1() and myFunction2()
    //
    //================

    nPick = Math.round(Math.random()) + 1; // 1 or 2

    pTest["myFunction" + nPick + "()"];

    ...or any other variation?

    Thanks,
    Richard

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    try
    pTest["myFunction" + nPick]()

    Musicman

  3. #3
    sucker for code
    Join Date
    Mar 2001
    Posts
    38
    Why not create just one function.. send nPick as an argument and let the function itself handle the dynamics..

    --------
    function myFunction(nPick){
    if (nPick==1){
    //do stuff
    } else {
    //do other stuff
    }
    }

    Call would be:

    nPick = int(Math.round(Math.random()) + 1); // 1 or 2

    pTest.myFunction(nPick)


    mc

  4. #4
    always for rent
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    307
    better yet, why don't you walk down the hall to jeremy's office and ask him! he might know...i heard he does some dynamic function calls. don't tell him i told you.
    :P
    jeremy

  5. #5
    sucker for code
    Join Date
    Mar 2001
    Posts
    38
    Why didn't I think of that...

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