actionscript3 whats the point of addFrameScript

2019-02-18 01:50发布

问题:

I want to ask about addFrameScript.

addFrameScript(0, frame1);   

what is this script means? why its 0?

is it possible to replace 0 with other number or word?

public function try()
{
    addFrameScript(0, frame1);
    return;

}// end function

If someone can help me to understand?

回答1:

This undocumented method is used to invoke a function when a MovieClip instance playhead reaches the given frame, in that case the 1st frame, 0 (0-based index). Your are of course limited to the available number of frames ; for instance, to add a script you the last frame, you would use :

mc.addFrameScript(mc.totalFrames-1, lastFrameReached);

function lastFrameReached():void {
    trace("stopping the animation");
    mc.stop();
}

Just think of it as a frame with some code inside the Flash authoring tool.



回答2:

A frame is a time slice in flash player. So if your fps is set to 12 fps, the script in that frame will be given attention (executed) for 1/12th of a second.

addFrameScript is hardly documented, perhaps to discourage it's use by developers. So basically, in code you initialize the timer class & manually manage your time slices.

Frames are again represented as a zero indexed array, with collection of executable called the frame script. So when you add the framescript yourself, you are simply doing what constructor of the Frame Class (internally) might do if you put it on the as3 panel of the frame in IDE.

In short, addFrameScript(0, frame1); is somthing in parallel to frameScripts[0] = frame1; where frameScripts could be an internal array.