n last month's article, I gave you an overview of some of Flash 8's most exciting features
. This month, I'll show you how easy it is to achieve a long-desired effectgradient masks.
Prior versions of Flash supported only 1-bit masks, meaning that only hard-edge masks were possible. In masks, pixels were considered either completely transparent or not transparent at all, with no gradations of opacity. Even if you used an alpha gradient in a mask, all non-transparent pixels would reveal the underlying content. In Flash 8, a new feature called "runtime bitmap caching" has changed all that.
Caching a MovieClip as a bitmap at runtime provides significant performance enhancements for complex MovieClips. It is less of a strain for your CPU to push pixels around the screen than to repeatedly recalculate the vector math and relevant properties (rotation, scale, alpha, etc.) that may be at work in your MovieClips.
|Figure 1. Hard vs. Alpha Gradient Masks: On the left, you can see a mask created in Flash MX 2004, where only 1-bit masks are supported. On the right, an alpha gradient in Flash 8 has given the same mask a soft edge.|
In addition, caching a MovieClip as a bitmap has other fun benefits. It allows a new level of compositing not possible in prior versions of Flash. In future articles, I will introduce you to runtime bitmap filters (drop shadow, glow, etc.), blend modes (akin to Photoshop blend modes or Director ink effects), and the new BitmapData class. The latter provides a variety of image manipulation methods, such as the ability to copy pixels from one image to another.
If you haven't yet tried the new Flash 8 player
, the old Flash mask seen in the left half of Figure 1
, can become the feathered beauty you see in the right half of Figure 1
. Hello soft wipes, and a host of other long-awaited effects! You'll need the new Flash 8 player to view the animations that accompany this article.
A Simple Example
This month, I'm going to show you how these simple lines of script...
maskee.cacheAsBitmap = true;
maskMC.cacheAsBitmap = true;
...can change the older Flash 1-bit solid mask shown on the left to the newer alpha gradient mask shown on the right.
Note that if you haven't downloaded and installed the Flash 8 player
, both Flash movies shown above will appear identical.