Movie Clip Scripts

I l @ ve RuBoard

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.

I l @ ve RuBoard


Sams Teach Yourself Flash MX ActionScript in 24 Hours
Sams Teach Yourself Flash MX ActionScript in 24 Hours
ISBN: 0672323850
EAN: 2147483647
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net