Movie Clip Scripts
You have already seen how to attach movie clips to frames and buttons. Now it is time to attach them to movie clips.
Movie clip scripts, like button scripts, use handlers. Instead of using the on keyword that button scripts use, we will use the onClipEvent keyword. Here is an example of a movie clip script:
onClipEvent (load) { trace("This clip has been loaded."); }
The load event happens when a movie clip first appears on the screen. It happens one time only.
Remember that when you stop the main timeline, the movie clips on the main timeline continue to animate. That fact is important to movie clip scripts because the next event, enterFrame, occurs every time a new frame is reached in the movie clip. Even when the main timeline is stopped, the movie clip continues to move along its own timeline, looping back to the beginning when it reaches its end. This means that enterFrame events happen at a continuous rate. Whenever an enterFrame event occurs, our onClipEvent (enterFrame) handler will be called. Here is a sample:
onClipEvent (enterFrame) { trace("This clip has entered a new frame."); }
The sample movie 06enterframe.fla contains a simple movie clip with this script attached to it. Run it, and your Output window will look like this:
This clip has been loaded. This clip has entered a new frame. This clip has entered a new frame. This clip has entered a new frame. This clip has entered a new frame.
This last line will repeat as long as you let the movie run. This timed repetition will allow us to do all sorts of things in the hours to come. It will be the bedrock of our scripts.