Programming ActionScript 3.0 |
|
|
|
| Display programming > Manipulating display objects > Caching display objects > When to enable caching | |||
Enabling caching for a display object creates a surface, which has several advantages, such as helping complex vector animations to render fast. There are several scenarios in which you will want to enable caching. It might seem as though you would always want to enable caching to improve the performance of your SWF files; however, there are situations in which enabling caching does not improve performance, or can even decrease it. This section describes scenarios in which caching should be used, and when to use regular display objects.
Overall performance of cached data depends on how complex the vector data of your instances are, how much of the data you change, and whether or not you set the opaqueBackground property. If you are changing small regions, the difference between using a surface and using vector data could be negligible. You might want to test both scenarios with your work before you deploy the application.
The following are typical scenarios in which you might see significant benefits when you enable bitmap caching.
opaqueBackground property of the background display object to true. The background is rendered as a bitmap and can be redrawn quickly, so that your animation plays much faster.scrollRect property). This enables fast pixel scrolling for the specified instance. When a user scrolls the display object instance, Flash shifts the scrolled pixels up and generates the newly exposed region instead of regenerating the entire text field.cacheAsBitmap property to true), each window is isolated and cached. Users can drag the windows so that they overlap each other, and each window doesn't need to regenerate the vector content.cacheAsBitmap property to true. For more information, see Alpha channel masking.Enabling bitmap caching in all of these scenarios improves the responsiveness and interactivity of the application by optimizing the vector graphics.
In addition, whenever you apply a filter to a display object, cacheAsBitmap is automatically set to true by Flash Player, even if you explicitly set it to false. If you clear all the filters from the display object, the cacheAsBitmap property returns to the value it was last set to.
Misusing this feature could negatively affect your SWF file. When you use bitmap caching, remember the following guidelines:
A cached bitmap can use significantly more memory than a regular display object. For example, if a Sprite instance on the Stage is 250 pixels by 250 pixels in size, when cached it might use 250 KB instead of 1 KB when it's a regular (un-cached) Sprite instance.
|
|
|
|