Chapter 7. Movie Clips

Introduction

Movie clips are at the very core of ActionScript. Without movie clips there would be no visual element to a Flash movie, so you can see why they are incredibly important.

Unlike many other object types, movie clips are never instantiated using a constructor function (the MovieClip class constructor is used only when creating subclasses, as in Recipe 12.12). Instead, movie clips are created in one of four ways:

  • Manually (at authoring time)

  • Attached from the Library at runtime, using attachMovie( )

  • Duplicated from another movie clip at runtime, using duplicateMovieClip( )

  • Created as a new, empty movie clip at runtime, using createEmptyMovieClip( )

Once a movie clip has been instantiated, it can be controlled in a variety of ways. The timelines of movie clips can be controlled using playback methods such as play( ), stop( ), and gotoAndPlay( ). Movie clips can be assigned actions that occur when certain events are triggered, and movie clip attributes can be controlled such that you can affect position, rotation, transparency, and so on.

To control a movie clip using ActionScript, you must know the target path to that instance. Each movie clip in a movie can be targeted in one of two ways: using a relative path or an absolute path. In relative paths there is a known relationship between the timeline from which the instructions are being issued and the movie clip to which they are being addressed. For example, a movie clip can address itself ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.