- It Works Like This
- Preparing to Work
- Using #include to Load ActionScript from a Text File
- Running Conditional Code with OnClipEvent
- The Time Zone Button Layer
- Using Functions to Repeat Common Tasks
- Keeping Time with the ActionScript Date Object
- Using Prototype to Extend the Date Object
- Updating in Real Time
- Updating the Mouse Time Zone
- Setting an Analogue Clock
- Setting a Row of Clocks
- Using setInterval to Update the Clocks
- About This Article
Running Conditional Code with OnClipEvent
A clip event enables you to add a unique block of code to an instance of a movie clip. You can also define the conditions under which the code will be run. The command syntax is made up of two sections. The keyword, contained within parenthesis, defines when the code or 'statement block' within the curly brackets will be run.
Look at the text file in your editor. You'll notice that it currently contains two empty clip events. Any code you add within the body (the area between the curly brackets) of the onClipEvent (load) section is run when the movie clip first appears. This is where you will put your function definitions and any initialization code.
Code placed within the body of the onClipEvent (enterFrame) section, however, will be run on the second frame and every subsequent frame thereafter. Although loads of conditions for clip events exist, these two are the most common.