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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Display programming<br />

mySprite.cacheAsBitmap = true;<br />

mySprite.cacheAsBitmapMatrix = new Matrix();<br />

Wh<strong>en</strong> you set this matrix property, you can apply the following additional transformation to the display object without<br />

recaching the object:<br />

Move or translate without pixel-snapping<br />

Rotate<br />

Scale<br />

Skew<br />

Change alpha (betwe<strong>en</strong> 0 and 100% transpar<strong>en</strong>cy)<br />

These transformations are applied directly to the cached bitmap.<br />

Setting an opaque background color<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

You can set an opaque background for a display object. For example, wh<strong>en</strong> your SWF has a background that contains<br />

complex vector art, you can set the opaqueBackground property to a specified color (typically the same color as the<br />

Stage). The color is specified as a number (commonly a hexadecimal color value). The background is th<strong>en</strong> treated as a<br />

bitmap, which helps optimize performance.<br />

Wh<strong>en</strong> you set cacheAsBitmap to true, and also set the opaqueBackground property to a specified color, the<br />

opaqueBackground property allows the internal bitmap to be opaque and r<strong>en</strong>dered faster. If you do not set<br />

cacheAsBitmap to true, the opaqueBackground property adds an opaque vector-square shape to the background of<br />

the display object. It does not create a bitmap automatically.<br />

The following example shows how to set the background of a display object to optimize performance:<br />

myShape.cacheAsBitmap = true;<br />

myShape.opaqueBackground = 0xFF0000;<br />

In this case, the background color of the Shape named myShape is set to red (0xFF0000). Assuming the Shape instance<br />

contains a drawing of a gre<strong>en</strong> triangle, on a Stage with a white background, this would show up as a gre<strong>en</strong> triangle with<br />

red in the empty space in the Shape instance’s bounding box (the rectangle that completely <strong>en</strong>closes the Shape).<br />

Of course, this code would make more s<strong>en</strong>se if it were used with a Stage with a solid red background. On another<br />

colored background, that color would be specified instead. For example, in a SWF with a white background, the<br />

opaqueBackground property would most likely be set to 0xFFFFFF, or pure white.<br />

Last updated 6/6/2012<br />

185

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

Saved successfully!

Ooh no, something went wrong!