ADOBE FLEX 3
Developer Guide
386
Scrolling bitmaps
Imagine you have created a street mapping application where each time the user moves the map you are required to
update the view (even if the map has been moved by just a few pixels).
One way to create this functionality would be to re-render a new image containing the updated map view each time
the user moves the map. Alternatively, you could create a large single image and the
scroll() method.
The
scroll() method copies an on-screen bitmap and then pastes it to a new offset location—specified by (x, y)
parameters. If a portion of the bitmap happens to reside off-stage, this gives the effect that the image has shifted.
When combined with a timer function (or an
enterFrame event), you can make the image appear to be animating
or scrolling.
The following example takes the previous perlin noise example and generates a larger bitmap image (three-fourths
of which is rendered off-stage). The
scroll() method is then applied, along with an enterFrame event listener that
offsets the image by one pixel in a diagonally downward direction. This method is called each time the frame is
entered and as a result, the offscreen portions of the image are rendered to the Stage as the image scrolls down.
import flash.display.Bitmap;
import flash.display.BitmapData;
var myBitmapDataObject:BitmapData = new BitmapData(1000, 1000, false, 0x00FF0000);
var seed:Number = Math.floor(Math.random() * 100);
var channels:uint = BitmapDataChannel.GREEN | BitmapDataChannel.BLUE;
myBitmapDataObject.perlinNoise(100, 80, 6, seed, false, true, channels, false, null);
var myBitmap:Bitmap = new Bitmap(myBitmapDataObject);
myBitmap.x = -750;
myBitmap.y = -750;
addChild(myBitmap);
addEventListener(Event.ENTER_FRAME, scrollBitmap);
function scrollBitmap(event:Event):void
{
myBitmapDataObject.scroll(1, 1);
}
Taking advantage of mipmapping
MIP maps (also known as mipmaps), are bitmaps grouped together and associated with a texture to increase runtime
rendering quality and performance. Flash Player 9.0.xx.0 and later versions and AIR implement this technology (the
process is called mipmapping), by creating optimized versions of varying scale of each bitmap (starting at 50%).
Flash Player and AIR create MIP maps for bitmaps (JPEG, GIF, or PNG files) that you display using the ActionScript
3.0 Loader class or a BitmapData object; Flash Player creates MIP maps for the bitmaps that you display using the
the ActionScript 2.0
loadMovie() function.
MIP maps are not applied to filtered objects or bitmap-cached movie clips. However, MIP maps are applied if you
have bitmap transformations within a filtered display object, even if the bitmap is within masked content.

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 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.