Asynchronous Bitmap Decoding

When loading large images within Flash Player, we now have control over when the image is actually decoded. Previous to Flash Player 11, loading large images or other files could adversely impact performance and responsiveness of the general user interface. We can now offload this process to a separate thread and make some choices around the image decode process by using the flash.system.ImageDecodingPolicy class.

This is set as the imageDecodingPolicy property of the flash.system.LoaderContext class and has two potential values. These values are defined by the constants ImageDecodingPolicy.ON_LOAD and ImageDecodingPolicy.ON_DEMAND. The ON_LOAD setting will actually decode the image even before the complete event fires. If ON_DEMAND is specified as the developer’s intended behavior, the image will not be decoded until it is needed by the runtime.

Image decode policy

Figure 2-2. Image decode policy

In this example, we load a high-resolution image into a Loader class and decode using this new behavior.

package {
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.system.ImageDecodingPolicy; import flash.text.TextField; import flash.text.TextFormat; import flash.events.ProgressEvent; [SWF(width="600", height="500", backgroundColor="#CCCCCC")] public class ImageDecoding extends ...

Get What's New in Flash Player 11 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.