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:
March 28th, 2008 at 12:39 pm
Ah, very nice. Didn’t even think about using a Delegate since its AS3 but its so obvious now. Feels a little weird though
April 16th, 2008 at 7:07 am
how about doing a something like
addFrameScript(”frame_name”,function)
can that be done?
April 16th, 2008 at 10:30 am
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/