Section 3.7. Your First Script


3.7. Your First Script

To prevent the movie from looping, you need to add an ActionScript method (also sometimes called a command or action). You'll use more ActionScript later, but for now, just add a simple stop( ) method and publish the movie again.

  1. In the timeline for animation.fla, add a new layer and drag it above the text and boxes layer folders.

  2. Rename the new layer actions. It is a good practice to keep the actions layer above all others in the timeline.


    Note: Placing your ActionScript on the top layer and naming the layer actions is a convention often used by Flash developers to make it easier to find the ActionScript in a movie (some developers name the layer "scripts" instead of "actions"). To follow best practices, don't put any content other than scripts in this layer.

  3. To prevent graphics from being added accidentally to the actions layer, lock the layer by clicking the second dot to the right of the layer name, under the lock icon.

  4. In the last frame of the timeline, insert a keyframe in the actions layer. (Locking the layer prevents you from adding graphics to the Stage for that layer, but you can still add keyframes and ActionScript to the layer.)

  5. With the last frame still selected, open the Actions panel by choosing Window Development Panels Actions, or by pressing F9.

  6. Figure 3-15. The Actions panel with a stop() method added to the Script panel

  7. Save your work and test your movie again.

  8. If you haven't created the .fla yourself or are having trouble doing so, open the animation_complete.swf file in the 03 folder of your working directory and watch the final result.

Frame Scripts

The frame script is the first of three main script types that you will learn about in the introductory ActionScript overviews herein. A simplified account of the frame script might describe it as serving two primary purposes.

First, it is used to perform administrative tasks such as defining information that you may need later in other scripts, including variables that store data and functions that collect instructions that should be executed only when called upon.

Second, a frame script is used to execute tasks passively. That is, rather than requiring active participation from the user, such as clicking a button or pressing a key, the script is executed during normal movie playback when the playhead reaches the frame in which the script resides. This is particularly useful for simple navigation methods, such as the stop( ) method used in this chapter.




Flash 8(c) Projects for Learning Animation and Interactivity
Flash 8: Projects for Learning Animation and Interactivity (OReilly Digital Studio)
ISBN: 0596102232
EAN: 2147483647
Year: 2006
Pages: 117

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