Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Working with Movie Clips > About caching and scrolling movie clips with ActionScript | |||
As your designs in Flash grow in size, whether you are creating an application or complex scripted animations, you need to consider performance and optimization. When you have content that remains static (such as a rectangle movie clip), Flash does not optimize the content. Therefore, when you change the position of the rectangle movie clip, Flash redraws the entire rectangle in Flash Player 7 and earlier.
In Flash 8 and later, you can cache specified movie clips and buttons to improve the performance of your SWF file. The movie clip or button is a surface, essentially a bitmap version of the instance's vector data, which is data that you do not intend to change much over the course of your SWF file. Therefore, instances with caching turned on are not continually redrawn as the SWF file plays, which lets the SWF file render quickly.
|
NOTE |
|
You can update the vector data, at which time the surface is recreated. Therefore, the vector data cached in the surface does not need to remain the same for the entire SWF file. |
You can use ActionScript to enable caching or scrolling and to control backgrounds. You can use the Property inspector to enable caching for a movie clip instance. To cache movie clips or buttons without using ActionScript, you can select the Use runtime bitmap caching option in the Property inspector instead.
The following table contains brief descriptions of the new properties for movie clip instances:
|
Property |
Description |
|---|---|
|
cacheAsBitmap |
Makes the movie clip instance cache a bitmap representation of itself. Flash creates a surface object for the instance, which is a cached bitmap instead of vector data. If you change the bounds of the movie clip, the surface is recreated instead of resized. For more information and an example, see Caching a movie clip. |
|
opaqueBackground |
Lets you specify a background color for the opaque movie clip instance. If you set this property to a numeric value, the movie clip instance has an opaque (nontransparent) surface. An opaque bitmap does not have an alpha channel (transparency), and renders faster. For more information and an example, see Setting the background of a movie clip. |
|
scrollRect |
Lets you quickly scroll movie clip content and have a window for viewing larger content. The movie clip's contents are cropped, and the instance scrolls with a specified width, height, and scroll offsets. This lets the user quickly scroll movie clip content and have a window that displays larger content than the Stage area. Text fields and complex content that you display in the instance can scroll faster because Flash does not regenerate the entire movie clip vector data. For more information and an example, see |
These three properties are independent of each other, however, the opaqueBackground and scrollRect properties work best when an object is cached as a bitmap. You only see performance benefits for the opaqueBackground and scrollRect properties when you set cacheAsBitmap to true.
To create a surface that's also scrollable, you must set the cacheAsBitmap and scrollRect properties for the movie clip instance. Surfaces can nest within other surfaces. The surface copies the bitmap onto its parent surface.
For information on alpha channel masking, which requires you to set the cacheAsBitmap property to true, see About alpha channel masking.
|
NOTE |
|
You cannot apply caching directly to text fields. You need to place text within a movie clip to take advantage of this feature. For a sample file, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and navigate to the ActionScript2.0/CacheBitmap folder to access the sample. |
For samples about applying bitmap caching to an instance and to scrolling text, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. The following samples are available:
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000867.html