A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Function

  1. #1
    Senior Member
    Join Date
    Jun 2007
    Posts
    204

    Function

    I've created a function that will be used multiple times...there will be overlap between the "called" function...how do I go about "attaching" the function to a particular MC?

    My thought was:

    [mc instance name].function ();

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You could put the function in a class and have the mc be an instance of that class.

    Or, you could use the call method of Function.
    Code:
    var myFunction:Function = function(arg1, arg2){
                                            //some stuff...
                                         };
    
    //to call as if attached to mc1:
    myFunction.call(mc1, arg1, arg2);
    Not that the call method doesn't make myFunction a property of mc1. If mc1 is dynamic, you could do that like this:
    Code:
    mc1.myFunction = myFunction;
    But, that's a little AS2-ish for my tastes.

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