• Keep in touch:
  • Linked In
  • Twitter
  • RSS

What is a movie clip?

A movie clip is a series of instructions that can be used to create animations that can be played independently of the time line of the main movie. This is useful as it allows you to re-use animations, for example when creating special effects for a game, rather than recreating the animation each time you want to display it. You can also nest movie clips inside another movie clip to create complex animations that would be difficult to create on a single time line.

Movie clips are treated as a single object. If you move, scale or rotate the clip then all the objects displayed inside (including nested movie clips) are also moved, scaled or rotated.

The time line of a movie clip is completely independent of the time line of the main movie or other movie clips. You can start, stop or move to different points in the movie clip time line at any time without affecting how the rest of the movie is displayed.

When playing streaming sounds in a movie clip the sound is automatically mixed by the Flash Player with sounds played on the main time line and other movie clips.

Creating a Movie Clip

When you create a movie clip you can only use the instructions that update the display list or play a sound. This means that all the instructions used to define objects must be added to the main movie, before you define the movie clip.

	movie.add(rectangle);
	
	final List<MovieTag> list = new ArrayList<MovieTag>();
	list.add(Place2.show(rectangle.getIdentifier(), 1, 0, 0));
	list.add(ShowFrame.getInstance());
    
	movie.add(new DefineMovieClip(identifier, list));

The instructions that can be used in the definition of a movie clip include: ShowFrame, Place, Place2, Remove, Remove2, DoAction, StartSound, FrameLabel, SoundStreamHead, SoundStreamHead2 or SoundStreamBlock. Other instructions are not allowed.

Assigning Names

When a movie clip is placed on the display list using the Place2 instruction, it can be assigned a name, which can then be used elsewhere in the movie to refer to the movie clip:

	place.setName(Place2.show(identifier, layer, x, y).setName("myClip"));

You can use the name in sequences of actions to control the movie clip:

    actions.add(new SetTarget("myclip"));
    actions.add(new GotoFrame(1));
    actions.add(BasicAction.PLAY);

More interestingly, if you create a set of nested movie clips then you can refer to each movie clip by its position in the hierarchy. For example consider the following set of nested clips:

  movie.swf
    clip (name = a)
      clip (name = b)

You can refer to a specific movie clip by setting the target using a path name created from the names of the clips:

  • "a" references the clip "a" from the main movie.
  • "a/b" references the clip "b" from the main movie.
  • "b" references the clip "b" from the movie clip "a".
  • ".." references the clip "a" from the movie clip "b".
  • "../.." references the main movie from the movie clip "b".

As with filesystem paths if you make the path absolute by prefixing "/", e.g. "/a/b" then you can reference the target movie clip from any location in the movie clip hierarchy.

The paths to the movie clips can be used when you define individual actions as well as from within Actionscript statements.