About Masking
In this chapter, you add several different kinds of effects to a simple website built entirely in Flash. You use several techniques to achieve these effects, one of which is by using masks.Masks are commonly used in Flash for a variety of creative effects. A mask is similar to a window placed over content, that reveals and hides different parts of the "masked" layers below it. You can see through a mask to the layer (or layers) beneath the mask - essentially, you cover up what you want to see. Anything solid on a mask layer is like the window, and the background area of the mask layer is the part that hides the content beneath (Figure 8.1).
Figure 8.1. The mask (solid part) is much like a window that you create to see through to the contents of the masked layer beneath.


Creating masks
Masks are simple to create. To create a simple mask, follow these steps using a new FLA file. Import an image into the Library (File > Import > Import to Library), and drag the image from the Library onto the Stage.Click Insert Layer on the Timeline to create a new layer. Make sure that the layer is above the layer with the image. On the new layer, select the Oval tool and draw a shape over a portion of the image.When you finish, right-click (Windows) or Control-click (Macintosh) the layer name of the top layer (contains the circle). Select Mask from the context menu. After you select this option, both layers lock and the bottom layer indents, as shown in the following figure. The layers must be locked for the mask to appear as it will in the final SWF file while in the authoring environment.
Figure 8.2. The oval mask lets you see through to the masked layer beneath that contains the image. Notice how the Timeline changes after you apply the mask.

Figure 8.3. Animate the mask movie clip. This animation uses motion and shape tweens, and a motion guide.
[View full size image]

Figure 8.4. Lock the mask and masked layer.
[View full size image]


Setting a mask using code
You can also set a mask using ActionScript. You can select a movie clip instance and set it as a mask for other objects on the Stage. The movie clip can still animate or interact with the user (such as have draggable properties, and so forth). Another advantage of using code to set a mask is you can toggle the mask on and off at runtime.Chapter 6 for information on how to make a movie clip draggable.Click Insert Layer to create a new layer on the Timeline. Select frame 1 of the Timeline, open the Actions panel, and then type the following ActionScript into the Script pane:
You can also remove a mask from myClip_mc at runtime. Create a button symbol, and drag an instance of it to the Stage. Select the instance, and give it the instance name my_btn in the Property inspector.Select frame 1 of the Timeline. Open the Actions panel again, and type the following ActionScript:
myClip_mc.setMask(mask_mc);
The first line of the button code (mask_mc._visible = false;) makes the mask movie clip invisible so it doesn't show over the top of the movie clip when you remove the mask. Then you remove the mask for myClip_mc by passing null to the setMask() method.
my_btn.onRelease = function() {
mask_mc._visible = false;
myClip_mc.setMask(null);
};
Limitations of masking
There are several limitations involved with using masks in your FLA files.If you need to mask device fonts, you must convert the text field into a movie clip and mask using a movie clip mask. If you use non-rectangular shapes to mask the text, the mask assumes the dimensions of the bounding box instead of the shape. Your visitors must have Flash Player 6 r40 or greater to see masked device fonts.You cannot mask a masking layer.Masks do not work inside buttons.Masks applied using the setMask() method can only mask movie clips.You cannot use alpha or semi-transparent fills with masks. Masks are always solid.You cannot mask using strokes, only fill shapes.
In this chapter's project, you use an animated mask to create a transition effect.
Masked Loading Animations
Sometimes animated masks are used to make shapes appear to "grow" in a SWF file or make it look like an image is "filling up" or appearing particularly for loading effects. To do this, animate a mask over the shape using a motion tween that makes the box larger in size to gradually cover the shape on the lower layer. Sometimes you might overlap two images (as in the previous example) and hide one while you make a second one appear, as shown in the following figure.A loading animation overlaps two images stacked above each other, and animates a mask to make the second"filled"image appear while the file loads.

Using Transitions for Effects
Transitions are one of the great benefits of using Flash to create a website. Transitions refer to an animation or effect that occurs when a visitor clicks on a new page in a Flash document. You can create transitions that simulate movement between two pages of content on a Flash website using motion and shape tweens or even frame-by-frame animation. There are many kinds of transition that you can add to a FLA file, too. A transition might be a simple effect that plays, or it might make the current page disappear and a new page appear.