addFrameScript with parameters

There is a little __undocumented__ function that can be very useful sometimes called addFrameScript. It allows you to specify a function that is called when the playhead of the Movieclip timeline enters the specified frame number. This can be a great improvement if you don’t want to write code directly on the timeline or if you don’t want to add an EnterFrame listener to the movieClip.

MovieClip.addFrameScript(frame_number:uint,function_to_call:Function)

Example:

Note: The frame number are zero based (0 to totalframes-1)

This function works well, but it’s impossible to pass arguments to the caller function. After a little research we found Ian Thomas delegate class.

Using delegate class is possible to call a function with arguments in situations that normally you couldn’t. So for addFrameScript we did:

3 Responses to “addFrameScript with parameters”

  1. Paulo Says:

    Ah, very nice. Didn’t even think about using a Delegate since its AS3 but its so obvious now. Feels a little weird though :)

  2. compelo Says:

    how about doing a something like
    addFrameScript(”frame_name”,function)

    can that be done?

  3. Ivan Valadares Says:

    i think what you want, is something like this :

    for (var i:int=0;i < mc.currentLabels.length;i++)
    {
    if (mc.currentLabels[i].name==”frame_name”)
    {
    mc.addFrameScript(mc.currentLabels[i].frame-1,function);
    }
    }

    Where mc is your movieclip and frame_name is your frame name, for more details check my previous post on frame labels:
    http://www.dreaminginflash.com/2007/09/26/11/

Leave a Reply