Table of Contents

MovieClip.setMask( ) Method Flash 6

assigns a movie clip as a mask for another clip
mc.setMask(maskMovieClip)

Arguments

maskMovieClip

A string indicating the path to the movie clip to be used as mc's mask. Because movie clip references are converted to paths when used in a string context, maskMovieClip can also be a movie clip object reference, as in mc.setMask(maskClip) versus mc.setMask("maskClip").

Description

The setMask( ) method assigns maskMovieClip as a mask for mc. When invoked, the content of maskMovieClip becomes a hole through which the content of mc is visible. Those portions of mc beneath occupied pixels of maskMovieClip are displayed, but portions of mc beneath empty pixels in maskMovieClip are hidden. Therefore, masks typically are created with black pixels in the areas where you want the masked clip, mc, to show through. For example, maskMovieClip may contain a filled black circle used as a spotlight on mc's content. To remove any mask currently applied to mc, call setMask( ) with a maskMovieClip parameter of null.

The following code sets flashlight_mc as the mask of darkroom_mc:

darkroom_mc.setMask(flashlight_mc);

And the following code removes the flashlight_mc mask:

darkroom_mc.setMask(null);

Shapes drawn with the movie clip drawing methods (beginFill( ), lineTo( ), curveTo( ), etc.) can be used in masks. As of Flash 6 (but not before), timelines of movie clips used as masks play normally. Each frame's content becomes the mask when the content is displayed. Mask clips can also be dragged, sized, and moved programmatically, and they can take movie clip and button-style event handlers. For example, a mask clip can define an onEnterFrame( ) handler that changes its position with each passing frame. Or, a mask clip can define onPress( ) and onRelease( ) handlers that drag and drop it, as follows:

darkroom_mc.setMask("spotlight_mc");
   
spotlight_mc.onPress = function () {
  trace("Dragging spotlight");
  this.startDrag();
}
   
spotlight_mc.onRelease = spotlight_mc.onReleaseOutside = function () {
  trace("Dropping spotlight");
  this.stopDrag();
}

When maskMovieClip defines at least one button event handler or contains a button object, no button events pass through to mc. That is, a masked clip cannot respond to button events when its mask defines a button event or contains a button.

If we apply a runtime mask to a movie clip used in an author-time mask layer, Flash removes the author-time mask and places the newly masked clip behind the layers it masked at authoring time.

Usage

Masks in Flash have several limitations:

See Also

MovieClip.beginFill( )


Table of Contents