Developer Guide
// Create a red square.
var redSquare1:Bitmap = new Bitmap(bmd2);
redSquare1.x = 0;
// Create a second red square.
var redSquare2:Bitmap = new Bitmap(bmd2);
redSquare2.x = 150;
redSquare2.y = 150;
// Define the point at the top-left corner of the bitmap.
var pt1:Point = new Point(0, 0);
// Define the point at the center of redSquare1.
var pt2:Point = new Point(20, 20);
// Define the point at the center of redSquare2.
var pt3:Point = new Point(160, 160);
trace(bmd1.hitTest(pt1, 0xFF, pt2)); // true
trace(bmd1.hitTest(pt1, 0xFF, pt3)); // false
Copying bitmap data
To copy bitmap data from one image to another, you can use several methods: clone(), copyPixels(),
copyChannel(), and draw().
As its name suggests, the
clone() method lets you clone, or sample, bitmap data from one BitmapData object to
another. When called, the method returns a new BitmapData object that is an exact clone of the original instance it
was copied from.
The following example clones a copy of an orange (parent) square and places the clone beside the original parent
import flash.display.Bitmap;
import flash.display.BitmapData;
var myParentSquareBitmap:BitmapData = new BitmapData(100, 100, false, 0x00ff3300);
var myClonedChild:BitmapData = myParentSquareBitmap.clone();
var myParentSquareContainer:Bitmap = new Bitmap(myParentSquareBitmap);
var myClonedChildContainer:Bitmap = new Bitmap(myClonedChild);
myClonedChildContainer.x = 110;
The copyPixels() method is a quick and easy way of copying pixels from one BitmapData object to another. The
method takes a rectangular snapshot (defined by the
sourceRect parameter) of the source image and copies it to
another rectangular area (of equal size). The location of the newly “pasted” rectangle is defined within the
destPoint parameter.
copyChannel() method samples a predefined color channel value (alpha, red, green, or blue) from a source
BitmapData object and copies it into a channel of a destination BitmapData object. Calling this method does not
affect the other channels in the destination BitmapData object.

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.