Imaging Lingo... er, ActionScript
Fans of Director's Imaging Lingo, Processing, and similar technologiesand now a whole community of Flash artistsare going to love this. The new BitmapData class provides a long list of bitmap manipulation methods. I won't go through the whole list in detail, as I'm planning on focusing on this in a future column.
The basis of the process is creating a new BitmapData object. This object can have dimensions, can be transparent or opaque, can be filled with color, and so on. Into this object, you can load a bitmap from the library, draw the contents of another BitmapData object or MovieClip, generate a noise pattern, or add a fill. You can copy pixels or a specific channel (red, green, blue, or alpha) from another BitmapData object. You can apply a filter from the aforementioned filters object, and merge (or dissolve pixels between) two BitmapData objects (see Figure 7).
|Figure 7. Additive Blending: The new BitmapData class makes additive blending possible. This example was inspired by a beautiful sphere by Emil Korngold.|
You can also examine bitmap data and build creative interactions. For example, you can get and set pixels, you can isolate areas of specific colorseither by finding a minimum bounding rectangle surrounding all pixels of that color, or even by checking the hitTest at a pixel level. Testing thresholds can be used to perform logical operations based on color. For example, some people have already attempted motion capture with Flash video. (See example collections in Related Resources, left column.)
Hand in hand with the BitmapData class, scripters will use the flash.geom class. This class makes it possible to specify rects and points for manipulating areas of an image, as well as create a transformation matrix that allows for simultaneous transforms of position, scale, and rotation.
Even without new features, developers are going to be interested in new performance improvements and MovieClip rendering options that will influence playback speed and file size. In general, playback performance is significantly improved in Flash Player 8 over previous versions. Perhaps the most tangible change is the introduction of the new MovieClip property, Cache As Bitmap.
Runtime Bitmap Caching
|Figure 8. Bitmap Caching: Bitmap caching can be enabled in the Properties panel (note the "Use runtime bitmap caching" checkbox) for continuous use, or can be enabled and disabled via ActionScript.|
One of the primary reasons that Flash is so much slower than many relevant bitmap-based technologies is that Flash must constantly recalculate all of the vector math required to display its shapes and symbols. If you could convert complicated vectors to bitmaps, they would display much quicker because those processor-intensive calculations would be dramatically reduced. The problem is, of course, that you lose the sharp vector qualities that prompted you to create your assets as vectors in the first place.
Runtime bitmap caching solves this problem. It temporarily caches and displays a bitmap version of a MovieClip, while still maintaining the integrity of the vector information. This allows the player to focus more on other changing elements of your file, without having to update the vector math of the cached MovieClip. This feature can easily be enabled in the Properties Panel (see Figure 8) or can be changed on the fly at any time via ActionScript. And because the vector information is preserved, you don't lose any opportunities for future vector manipulation.
When possible, enabling the ActionScript property MovieClip.opaqueBackground can improve performance even more. This is somewhat equivalent to the reduction in processor drain when switching from a PNG with a transparent background to a JPEG. If Flash can temporarily stop calculating opacities, for example, of a cached bitmap, performance can be further boosted.
Another cool performance optimization, and creative option, is the new MovieClip.scrollRect property. This allows you to quickly scroll movie clips within a cropped rectangle defined by the property. Complex MovieClips and text fields scroll much faster because a bitmap of the clip is scrolled instead of having to recalculate the entire clip from vector data. Just like Director's sprite rect, the scroll rect is based on the MovieClip's bounding rectangle with 0,0 residing in the upper left corner of the clip.
Type Rendering Improvements
Figure 9. Better Anti-aliasing: These examples of various typical fonts at a variety of sizes demonstrate the improved Flash type rendering engine.
Figure 10. Anti-alias Presets: Two new anti-alias presets have been added to the type rendering options, as well as an option to define your own custom anti-alias values.
Developers and designers alike will rejoice in the improved type rendering engine in Flash 8. Fonts have been a perennial weakness of Flash since its inception and this is the first major improvement. In most cases, the new engine makes everyday fonts look vastly better at smaller file sizeseven as small as 6 pt. Figure 9
shows four fonts in sizes from 6 to 10 points. Some fonts fare better than others, but all are significantly improved over prior versions of Flash.
Two presets in the Properties panel allow for improved anti-aliasing optimized for animation and readability (see Figure 10). You can also customize thickness and sharpness values for your own anti-alias values. This makes it possible for you to create settings that are optimized for specific fonts.
ActionScript's new TextRenderer class makes this even easier. For a given font, you can define the anti-alias type (normal, text field control, or advanced), the color type (dark or light), the font style (bold, italic, or bold/italic), and the grid fitting, or type hinting, type (align verticals along the pixel or sub-pixel gridthe latter best for LCD displays). With the "advanced" anti-alias type, you can even define the inside (opaque) and outside (transparent) cutoff thresholds at which the anti-aliasing is applied.