Gradient mask mean a mask that fades with the MovieClip masked, and not suddenly finished. For being more understandable see in the below how a gradient mask (the left circle) or a  non-gradient mask (the right circle) will look.

Gradient and non-gradient mask in Flash

 Ok, how to do this? Just follow the next 6 steps:

1. Create a new flash document and set for it 300×300 dimensions. Create two more layers and rename them from top to bottom: actions, mask, background.

Layers in Flash 8

2. In the first frame of the background layer import a 300×300 picture you want to mask. Choose File >> Import >> Import to Stage (Ctrl+R). Select the picture and go to Modify >> Convert to Symbol (F8). In the Convert to Symbol window that appears choose MovieClip as Type, center for Registration point, put it the name bgMC and press OK button. While the picture is still selected go to the Properties panel and give it an instance name of bg_mc.

Convert to Symbol in Flash 8

3. Select the Oval Tool (O) from the Tools panel, go to the Properties panel and choose none for Stroke color and white #FFFFFF for Fill color. Now go to the first frame of the mask layer and draw a circle (hold pressed the Shift key to draw a perfect circle). Click the circle to select it,go to the Properties panel and set W:300.0 and H:300.0. Then go to the Align panel and center the circle both horizontal and vertical.

How to align an object in Flash

4. Now let’s put it some gradient. Having the circle selected go to Color panel and choose the Color Mixer tab. Choose Radial as Type and #FFFFFF for the first color and #FFFFFF, Alpha 0% for the second color (see next pictures).

Flash Color Mixer panel     Flash alpha property

5. Now I will convert the circle into a MovieClip named maskMC(see step 2). While the circle is still selected go to the Properties panel and give it an instance name of mask_mc.

6. Now go to the first frame of the actions layer and open the Actions panel (F9). Put the following ActionScript code:

bg_mc.cacheAsBitmap=true;
mask_mc.cacheAsBitmap=true;
bg_mc.setMask(mask_mc);

What does this code? I will start with the end: the third line just sets mask_mc as mask for bg_mc.

The first two lines of ActionScript do the same thing: sets to true the cacheAsBitmap property of bg_mc and mask_mc movieclips. MovieClip.cacheAsBitmap property tells Flash Player to cache an internal bitmap representation of the MovieClip reffered is it is set to true.

That’s all!

3 Responses to “Flash 8 gradient mask using cacheAsBitmap property”
  1. picklepuss says:

    Huh… Your blog is nice in general, but this very post… It is brilliant!!! It can be never better.

  2. Greg says:

    Awesome! Ahahaha! Stop it, you’re killing me! Anyway, I’m glad I’m not the only one who thought this is great.

  3. tammmmm says:

    very helpful!! thanks alot!

Leave a Reply