Basics of movie clips

Introduction to working with movie clips

Movie clips are a key element for people who create animated content with the Flash authoring tool and want to control that content with ActionScript. Whenever you create a movie clip symbol in Flash, Flash adds the symbol to the library of that Flash document. By default, this symbol becomes an instance of the MovieClip class, and as such has the properties and methods of the MovieClip class.

When an instance of a movie clip symbol is placed on the Stage, the movie clip automatically progresses through its timeline (if it has more than one frame) unless its playback is altered using ActionScript. It is this timeline that distinguishes the MovieClip class, allowing you to create animation through motion or shape tweens through the Flash authoring tool. By contrast, with a display object that is an instance of the Sprite class, you can create animation only by programmatically changing the object’s values.

In previous versions of ActionScript, the MovieClip class was the base class of all instances on the Stage. In ActionScript 3.0, a movie clip is only one of many display objects that can appear on the screen. If a timeline is not necessary for the function of a display object, using the Shape class or Sprite class in lieu of the MovieClip class may improve rendering performance. For more information on choosing the appropriate display object for a task, see Choosing a DisplayObject subclass.

Common movie clip tasks

The following common movie clips tasks are described in this chapter:

  • Making movie clips play and stop

  • Playing movie clips in reverse

  • Moving the playhead to specific points in a movie clip’s timeline

  • Working with frame labels in ActionScript

  • Accessing scene information in ActionScript

  • Creating instances of library movie clip symbols using ActionScript

  • Loading and controlling external SWF files, including files created for previous Flash Player versions

  • Building an ActionScript system for creating graphical assets to be loaded and used at run time

Important concepts and terms

The following reference list contains important terms used in this chapter:

  • AVM1 SWF: A SWF file created using ActionScript 1.0 or ActionScript 2.0, usually targeting Flash Player 8 or earlier.

  • AVM2 SWF: A SWF file created using ActionScript 3.0 for Adobe Flash Player 9 or later or Adobe AIR.

  • External SWF: A SWF file that is created separately from the project SWF file and is intended to be loaded into the project SWF file and played back within that SWF file.

  • Frame: The smallest division of time on the timeline. As with a motion picture filmstrip, each frame is like a snapshot of the animation in time, and when frames are played quickly in sequence, the effect of animation is created.

  • Timeline: The metaphorical representation of the series of frames that make up a movie clip’s animation sequence. The timeline of a MovieClip object is equivalent to the timeline in the Flash authoring tool.

  • Playhead: A marker identifying the location (frame) in the timeline that is being displayed at a given moment.

Working through in-chapter examples

As you’re working through the chapter, you may want to test some of the example code listings for yourself. Because this chapter is about working with movie clips in ActionScript, essentially all the code listings in this chapter are written with the idea of manipulating a movie clip symbol that has been created and placed on the Stage. Testing the sample will involve viewing the result in Flash Player or AIR to see the effects of the code on the symbol. To test the code listings in this chapter:

  1. Create an empty Flash document.

  2. Select a keyframe in the timeline.

  3. Open the Actions panel and copy the code listing into the Script pane.

  4. Create a movie clip symbol instance on the Stage. For example, draw a shape, select it, choose Modify > Convert to symbol, and give the symbol a name.

  5. With the movie clip selected, in the Property inspector, give it an instance name. The name should match the name used for the movie clip in the example code listing—for example, if the code listing manipulates a movie clip named myMovieClip, you should name your movie clip instance myMovieClip as well.

  6. Run the program using Control > Test Movie.

    On the screen you will see the results of the code manipulating the movie clip as specified in the code listing.

Other techniques for testing example code listings are explained in more detail in Testing in-chapter example code listings.