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 />

Wh<strong>en</strong> to avoid using bitmap caching<br />

Using this feature in the wrong circumstances can negatively affect the performance of your SWF file. Wh<strong>en</strong> you use<br />

bitmap caching, remember the following guidelines:<br />

Do not overuse surfaces (display objects with caching <strong>en</strong>abled). Each surface uses more memory than a regular<br />

display object, which means that you should only <strong>en</strong>able surfaces wh<strong>en</strong> you need to improve r<strong>en</strong>dering<br />

performance.<br />

A cached bitmap can use significantly more memory than a regular display object. For example, if a Sprite instance<br />

on the Stage is 250 pixels by 250 pixels in size, wh<strong>en</strong> cached it might use 250 KB instead of 1 KB wh<strong>en</strong> it’s a regular<br />

(un-cached) Sprite instance.<br />

Avoid zooming into cached surfaces. If you overuse bitmap caching, a large amount of memory is consumed (see<br />

previous bullet), especially if you zoom in on the cont<strong>en</strong>t.<br />

Use surfaces for display object instances that are largely static (non-animating). You can drag or move the instance,<br />

but the cont<strong>en</strong>ts of the instance should not animate or change a lot. (Animation or changing cont<strong>en</strong>t are more likely<br />

with a MovieClip instance containing animation or a Video instance.) For example, if you rotate or transform an<br />

instance, the instance changes betwe<strong>en</strong> the surface and vector data, which is difficult to process and negatively<br />

affects your SWF file.<br />

If you mix surfaces with vector data, it increases the amount of processing that Flash Player and AIR (and<br />

sometimes the computer) need to do. Group surfaces together as much as possible—for example, wh<strong>en</strong> you create<br />

windowing applications.<br />

Do not cache objects whose graphics change frequ<strong>en</strong>tly. Every time you scale, skew, rotate the display object,<br />

change the alpha or color transform, move child display objects, or draw using the graphics property, the bitmap<br />

cache is redrawn. If this happ<strong>en</strong>s every frame, the runtime must draw the object into a bitmap and th<strong>en</strong> copy that<br />

bitmap onto the stage—which results in extra work compared to just drawing the uncached object to the stage. The<br />

performance tradeoff of caching versus update frequ<strong>en</strong>cy dep<strong>en</strong>ds on the complexity and size of the display object<br />

and can only be determined by testing the specific cont<strong>en</strong>t.<br />

Enabling bitmap caching<br />

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

To <strong>en</strong>able bitmap caching for a display object, you set its cacheAsBitmap property to true:<br />

mySprite.cacheAsBitmap = true;<br />

After you set the cacheAsBitmap property to true, you might notice that the display object automatically pixel-snaps<br />

to whole coordinates. Wh<strong>en</strong> you test the SWF file, you should notice that any animation performed on a complex<br />

vector image r<strong>en</strong>ders much faster.<br />

A surface (cached bitmap) is not created, ev<strong>en</strong> if cacheAsBitmap is set to true, if one or more of the following occurs:<br />

The bitmap is greater than 2880 pixels in height or width.<br />

The bitmap fails to allocate (because of an out-of-memory error).<br />

Cached bitmap transform matrices<br />

Adobe AIR 2.0 and later (mobile profile)<br />

In AIR applications for mobile devices, you should set the cacheAsBitmapMatrix property wh<strong>en</strong>ever you set the<br />

cacheAsBitmap property. Setting this property allows you to apply a wider range of transformations to the display<br />

object without triggering rer<strong>en</strong>dering.<br />

Last updated 6/6/2012<br />

184

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

Saved successfully!

Ooh no, something went wrong!