I just filed a feature request for Flash player, asking for a cacheAsBitmapOptions property on display objects. The intent behind this is to make the current cacheAsBitmap functionality more useful. Currently, when you use cacheAsBitmap, the cache is redrawn any time you modify the transform the display object in any way other than translation (moving it in x/y). For example, if you rotate, alpha, or scale your display object it forces the cache to redraw.
It’s often useful to maintain a cache through other transformations, such as rotation, changes to alpha, and scaling. I frequently implement this functionality manually by drawing the display object to a BitmapData, and swapping the Bitmap for the original Sprite. This works, but it’s very clumsy, and requires a lot of manual management.
In conjunction with this, it would be useful to specify the resolution that the bitmap cache is created at, as a scale multiplier of the DO on stage.
The cacheAsBitmapOptions feature I am proposing would let you programmatically specify what transformations would result in a cache redraw. For example:
import flash.display.CacheAsBitmapOptions; // name based on NetStreamPlayOptions var myOpts:CacheAsBitmapOptions = new CacheAsBitmapOptions(); myOpts.updateOnRotation = false; myOpts.updateOnAlpha = false; myOpts.updateOnScale = false; myOpts.cacheScale = 2; characterSprite.cacheAsBitmapOptions = myOpts; // passing null would revert to defaults. otherSprite.cacheAsBitmapOptions = new CacheAsBitmapOptions(2, false, false, false); |
If you think this functionality would be useful for your projects, feel free to vote it up. The bug is filed in the Flash Player bugbase as bug #FP-2524.
On Monday I will post a blog entry walking through how to implement this type of functionality manually, with a handy helper class.