Movie Clip Scripts

written by: Milan Midovich; article published: year 2007, month 06;


In: Root » Computers and technology » Flash » Movie Clip Scripts

Dutch French Spanish Portuguese Italian German Japanese Chinese Korean Russian Arabic Bookmark and Share this Article

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.

Disclaimer

1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here.

link to this article