Using movie clips as masks

You can use a movie clip as a mask to create a hole through which the contents of another movie clip are visible. The mask movie clip plays all the frames in its timeline, the same as a regular movie clip. You can make the mask movie clip draggable, animate it along a motion guide, use separate shapes within a single mask, or resize a mask dynamically. You can also use ActionScript to turn a mask on and off.

You cannot use a mask to mask another mask. You cannot set the _alpha property of a mask movie clip. Only fills are used in a movie clip that is used as a mask; strokes are ignored.

To create a mask:

  1. Create a square on the Stage with the Rectangle tool.
  2. Select the square and press F8 to convert it into a movie clip.

    This instance is your mask.

  3. In the Property inspector, type mask_mc in the Instance Name text box.

    The masked movie clip is revealed under all opaque (nontransparent) areas of the movie clip acting as the mask.

  4. Select Frame 1 in the Timeline.
  5. Open the Actions panel (Window > Actions) if it isn't already open.
  6. In the Actions panel, enter the following code:
    System.security.allowDomain("http://www.helpexamples.com");
    
    this.createEmptyMovieClip("img_mc", 10);
    var mclListener:Object = new Object();
    mclListener.onLoadInit = function(target_mc:MovieClip):Void {
        target_mc.setMask(mask_mc);
    }
    var my_mcl:MovieClipLoader = new MovieClipLoader();
    my_mcl.addListener(mclListener);
    my_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);
    
  7. Select Control > Test Movie to test the document.

    An external JPEG image loads into the SWF file at runtime, and is masked by the shape you drew previously on the Stage.

For detailed information, see setMask (MovieClip.setMask method) in the ActionScript 2.0 Language Reference.