How to Use Frame Labels in Flash CS5
In Adobe Flash Creative Suite 5, many ActionScript statements, like goto statements, reference exact frame numbers to navigate the Flash CS5 timeline. If you happen to change the placement of something on your timeline (such as the start or end of an animation), frame numbers may become inaccurate. For cases like these, you can assign names directly to keyframes on the timeline that you can call directly from ActionScript.
Frame labels are familiar names you can assign to any keyframe (such as start, end, or big_finale). You can then tell ActionScript to jump to these frames by name as an alternative to using a frame number. If the location of the named frame changes, scripts still function as long as the label name is the same. When you move a keyframe, the label you assign to it moves with it.
Here’s how to modify a button to use a frame label instead of a frame number:
Create a new layer on the timeline and assign it the name Labels.
This name is arbitrary, but it’s always a good idea to name layers as intuitively as possible.
Select frame 1 of your new layer.
Be sure to select the correct frame and only that frame.
Enter top in the text box shown in the Label area of the Property inspector.
For example, we assigned this keyframe the label name top.
Select frame 22 of your Actions layer and choose Window→Actions to open the Actions panel (if it’s not already open).
Add a gotoAndPlay() statement here.
Locate the line that reads gotoAndPlay(5). Replace 5 with the name of the new frame label (top) in double quotes.
The code now reads
Choose Control→Test Movie to preview your changes.
Click the Rewind button and you see the animation jump to frame 5 and stop just as it did earlier. This time, however, the code uses a frame label instead of an absolute frame number.
Now, no matter where you move the keyframe, the script follows automatically as long as the frame label remains the same.