Ryan Yacyshyn


The Undocumented “addFrameScript” Method

By Ryan Yacyshyn | Published May 9th, 2008

There's a useful function inside the MoveClip class (AS3) that will add script inside a Movieclip on a specific frame without actually having to add it manually to the timeline. This is great if, say you have someone working purely on animation and then someone else working on the interface to hold/play/control the animation. A lot of times this person will need to know when then animation has completed and will therefore need to add script inside the MovieClip animation. The addFrameScript can do this for you without altering the animation and re-exporting, etc.

The function takes two parameters: frame number to place the script (0 based) and the function name to call.

public function addFrameScript (frame:uint, notify:Function):void;

Example:

    // animation is the name of the movieclip.. 
    animation.addFrameScript (77, onAnimationEnd);      

    // function called when playhead reaches 76.. 
    private function onAnimationEnd ():void { 
        trace ("onAnimationEnd.."); 
    }