
In many SWF applications, developers need a way to programmatically monitor a timeline as it is played back so the code can take some action when a frame label or the end of the timeline is reached. Techniques for achieving this, however, have often conflicted with the design goal of separating timelines from actions.
In the past decade Adobe Flash has grown from a simple animation tool into a comprehensive authoring environment for creating rich content. Nowadays many rich media agencies have implemented a workflow where multiple people in different roles—including Flash designers and developers—can simultaneously work together on one project, and projects are split into many different FLA and ActionScript files that all fit a specific framework or conceptual structure.
As a result, it has become a key best practice to use FLA files primarily as a collection of multimedia elements and timeline animations, and to embody all logic in external ActionScript files. To enable this workflow, Flash CS3 Professional introduced the Document class as a default mechanism to link a FLA file to external ActionScript code.
Overall it has become pretty easy to separate timelines from actions or code. However, there is unfortunately one exception to the rule.
Consider the following scenario: A developer would like to run a piece of code after a certain timeline has played to a specific point, which is marked with a label. How does he know exactly when this point has been reached? To solve this problem, the developer might place the following action on a timeline inside a FLA file:
dispatchEvent(new Event("animationHasFinished"));
Although there is nothing invalid about this approach, it does have drawbacks. For developers, timeline actions are harder to author, adjust, and locate than code inside external ActionScript files. Many designers will also find this approach too technical. Lastly, it simply violates the principle of keeping your actions and timelines separated (yes, we "Flashers" are proud people).
At Refunk, where I work, we have developed a small utility that elegantly solves this problem. The TimelineWatcher class enables a developer's code to watch a timeline as it is played back and be notified when a frame label or the end of the timeline has been reached. By using frame labels as hooks—cue points, as in web video—timelines and actions can now be truly separated.
To complete this tutorial, you will need to install the following software and files:
You should have a good understanding of Adobe Flash Professional and ActionScript 3.0.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License
Bobby van der Sluis works at Refunk, an award-winning creative agency based in Amsterdam, The Netherlands, that specializes in Adobe Flash. He is a big fan of both web standards and Adobe Flash, and occasionally has the urge to write about these topics on his personal website or for online magazines. He is the creator of UFO and coauthor of SWFObject 2—two well-known, open-source JavaScript libraries for detecting Adobe Flash Player and embedding SWF files into web pages.