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

The DisplayObject class’s opaqueBackground property and scrollRect property are related to bitmap caching using<br />

the cacheAsBitmap property. Although these three properties are indep<strong>en</strong>d<strong>en</strong>t of each other, the opaqueBackground<br />

and scrollRect properties work best wh<strong>en</strong> an object is cached as a bitmap—you see performance b<strong>en</strong>efits for the<br />

opaqueBackground and scrollRect properties only wh<strong>en</strong> you set cacheAsBitmap to true. For more information<br />

about scrolling display object cont<strong>en</strong>t, see “Panning and scrolling display objects” on page 178. For more information<br />

about setting an opaque background, see “Setting an opaque background color” on page 185.<br />

For information on alpha channel masking, which requires you to set the cacheAsBitmap property to true, see<br />

“Masking display objects” on page 190.<br />

Wh<strong>en</strong> to <strong>en</strong>able caching<br />

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

Enabling caching for a display object creates a surface, which has several advantages, such as helping complex vector<br />

animations to r<strong>en</strong>der fast. There are several sc<strong>en</strong>arios in which you will want to <strong>en</strong>able caching. It might seem as<br />

though you would always want to <strong>en</strong>able caching to improve the performance of your SWF files; however, there are<br />

situations in which <strong>en</strong>abling caching does not improve performance, or can ev<strong>en</strong> decrease it. This section describes<br />

sc<strong>en</strong>arios in which caching should be used, and wh<strong>en</strong> to use regular display objects.<br />

Overall performance of cached data dep<strong>en</strong>ds on how complex the vector data of your instances are, how much of the<br />

data you change, and whether or not you set the opaqueBackground property. If you are changing small regions, the<br />

differ<strong>en</strong>ce betwe<strong>en</strong> using a surface and using vector data could be negligible. You might want to test both sc<strong>en</strong>arios<br />

with your work before you deploy the application.<br />

Wh<strong>en</strong> to use bitmap caching<br />

The following are typical sc<strong>en</strong>arios in which you might see significant b<strong>en</strong>efits wh<strong>en</strong> you <strong>en</strong>able bitmap caching.<br />

Complex background image: An application that contains a detailed and complex background image of vector data<br />

(perhaps an image where you applied the trace bitmap command, or artwork that you created in Adobe<br />

Illustrator®). You might animate characters over the background, which slows the animation because the<br />

background needs to continuously reg<strong>en</strong>erate the vector data. To improve performance, you can set the<br />

opaqueBackground property of the background display object to true. The background is r<strong>en</strong>dered as a bitmap<br />

and can be redrawn quickly, so that your animation plays much faster.<br />

Scrolling text field: An application that displays a large amount of text in a scrolling text field. You can place the<br />

text field in a display object that you set as scrollable with scrolling bounds (the scrollRect property). This <strong>en</strong>ables<br />

fast pixel scrolling for the specified instance. Wh<strong>en</strong> a user scrolls the display object instance, Flash Player or AIR<br />

shifts the scrolled pixels up and g<strong>en</strong>erates the newly exposed region instead of reg<strong>en</strong>erating the <strong>en</strong>tire text field.<br />

Windowing system: An application with a complex system of overlapping windows. Each window can be op<strong>en</strong> or<br />

closed (for example, web browser windows). If you mark each window as a surface (by setting the cacheAsBitmap<br />

property to true), each window is isolated and cached. Users can drag the windows so that they overlap each other,<br />

and each window doesn’t need to reg<strong>en</strong>erate the vector cont<strong>en</strong>t.<br />

Alpha channel masking: Wh<strong>en</strong> you are using alpha channel masking, you must set the cacheAsBitmap property<br />

to true. For more information, see “Masking display objects” on page 190.<br />

Enabling bitmap caching in all of these sc<strong>en</strong>arios improves the responsiv<strong>en</strong>ess and interactivity of the application by<br />

optimizing the vector graphics.<br />

In addition, wh<strong>en</strong>ever you apply a filter to a display object, cacheAsBitmap is automatically set to true, ev<strong>en</strong> if you<br />

explicitly set it to false. If you clear all the filters from the display object, the cacheAsBitmap property returns to the<br />

value it was last set to.<br />

Last updated 6/6/2012<br />

183

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

Saved successfully!

Ooh no, something went wrong!