Just the other day, I was helping a coworker with some ActionScript in Flash CS5 when I was reminded of a lesson I had learned a few years ago. We had animation not working as expected in a .swf and when I looked at the keyframes, I knew instantly why. Read on to see the problem and how to fix it...
The important thing to remember when assigning ActionScript to a blank keyframe on the timeline in Flash (any version), you need to consider the frames that follow the keyframe. ActionScript on a blank keyframe works much the same as a keyframe with content assigned on the stage.
If you follow the rule of thumb recommended by most Flash developers, then I assume you are putting your ActionScript code on it's own layer and assigning it to a blank keyframe, right? But, if you fail to follow that blank keyframe with another blank keyframe, then that code will cover multiple frames if additional frames are inserted. This is something that might happen automatically if you add a blank keyframe further down the timeline and not even realize it.
So, if you had say a "stop();" command at the beginning of the timeline to halt playback until called upon later to play, you might be seeing nothing happen upon playback even though you have told the timeline to play later by another ActionScript command.
The reason this might happen? The keyframe with the "stop();" command is covering more than one frame. It might be covering all the frames up to the point of where you placed the command for play, thus leaving nothing to play back or skipping frames in the timeline that should have played. Example seen below.
A simple blank keyframe is all that is needed to fix this problem. A blank keyframe placed in frame 2 will stop the ActionScript at frame 1. The "stop();" command was attached to frames 1 through 14 but by inserting the extra blank keyframe, it has been confined to only one frame.
Now, if this timeline was in a movie clip, we could reference the movie clip which is stopped on frame 1 and tell it to play. It will now play through until it loops or hits another "stop();" command. Without the extra keyframe, the timeline movement was stuck to one frame.
It's one of those little things you eventually learn as you use more and more ActionScript in your Flash creations. Flash is fun but it can be tedious and finding a good methods or techniques in how you create will make the process easier and quicker. End result? Not sweating it and enjoying more of the fun stuff. More tips to come... keep Flashin'!