13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Display programming<br />

The display object that is acting as a mask can be draggable, animated, resized dynamically, and can use separate shapes<br />

within a single mask. The mask display object doesn’t necessarily need to be added to the display list. However, if you<br />

want the mask object to scale wh<strong>en</strong> the Stage is scaled or if you want to <strong>en</strong>able user interaction with the mask (such as<br />

user-controlled dragging and resizing), the mask object must be added to the display list. The actual z-index (front-toback<br />

order) of the display objects doesn’t matter, as long as the mask object is added to the display list. (The mask<br />

object will not appear on the scre<strong>en</strong> except as a mask.) If the mask object is a MovieClip instance with multiple frames,<br />

it plays all the frames in its timeline, the same as it would if it were not serving as a mask. You can remove a mask by<br />

setting the mask property to null:<br />

// remove the mask from mySprite<br />

mySprite.mask = null;<br />

You cannot use a mask to mask another mask. You cannot set the alpha property of a mask display object. Only fills<br />

are used in a display object that is used as a mask; strokes are ignored.<br />

AIR 2<br />

If a masked display object is cached by setting the cacheAsBitmap and cacheAsBitmapMatrix properties, the mask<br />

must be a child of the masked display object. Similarly, if the masked display object is a desc<strong>en</strong>d<strong>en</strong>t of a display object<br />

container that is cached, both the mask and the display object must be desc<strong>en</strong>d<strong>en</strong>ts of that container. If the masked<br />

object is a desc<strong>en</strong>d<strong>en</strong>t of more than one cached display object container, the mask must be a desc<strong>en</strong>d<strong>en</strong>t of the cached<br />

container closest to the masked object in the display list.<br />

About masking device fonts<br />

You can use a display object to mask text that is set in a device font. Wh<strong>en</strong> you use a display object to mask text set in<br />

a device font, the rectangular bounding box of the mask is used as the masking shape. That is, if you create a nonrectangular<br />

display object mask for device font text, the mask that appears in the SWF file is the shape of the<br />

rectangular bounding box of the mask, not the shape of the mask itself.<br />

Alpha channel masking<br />

Alpha channel masking is supported if both the mask and the masked display objects use bitmap caching, as shown here:<br />

// maskShape is a Shape instance which includes a gradi<strong>en</strong>t fill.<br />

mySprite.cacheAsBitmap = true;<br />

maskShape.cacheAsBitmap = true;<br />

mySprite.mask = maskShape;<br />

For instance, one application of alpha channel masking is to use a filter on the mask object indep<strong>en</strong>d<strong>en</strong>tly of a filter<br />

that is applied to the masked display object.<br />

In the following example, an external image file is loaded onto the Stage. That image (or more accurately, the Loader<br />

instance it is loaded into) will be the display object that is masked. A gradi<strong>en</strong>t oval (solid black c<strong>en</strong>ter fading to<br />

transpar<strong>en</strong>t at the edges) is drawn over the image; this will be the alpha mask. Both display objects have bitmap caching<br />

turned on. The oval is set as a mask for the image, and it is th<strong>en</strong> made draggable.<br />

Last updated 6/6/2012<br />

191

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!