MovieClip.addFrameScript()

Not sure why I’ve only just come across this but there’s any an undocumented AS3 function of MovieClip called addFrameScript which turns out to be pretty useful. It allows you to execute any function when the playhead of the MovieClip reaches a certain frame and the arguments a int based on zero-based range for the frame number and a Fuction. For example you can make a class which automatically stops when it reaches the end of it’s animation.

1
2
3
4
5
6
7
8
9
10
11
12
13
package  {
    import flash.display.MovieClip;
   
    public class MovieClipAutoStop extends MovieClip{
       
        public function MovieClipAutoStop() {
            super();
            addFrameScript(totalFrames - 1, stop);
        }
       
    }

}

This kind of functionality means you should rarely have to program on the timeline and helps separate the design and coding process a little bit further, saving you the worry of clumsy designers deleting your ActionScript and generally breaking all your shit.

Warning: it is undocumented so I guess there’s no guarantee it’ll stick around but let’s hope so!

Tags: , , , ,

Leave a Reply