Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > BitmapData (flash.display.BitmapData) > clone (BitmapData.clone method) | |||
public clone() : BitmapData
Returns a new BitmapData object that is a clone of the original instance with an exact copy of the contained bitmap.
Availability: ActionScript 1.0; Flash Player 8
flash.display.BitmapData - A new BitmapData object that is identical to the original.
The following example creates three BitmapData objects and compares them. You can create the bitmap_1 instance by using the BitmapData constructor. You create the bitmap_2 instance by setting it equal to bitmap_1. You create he clonedBitmap instance by cloning bitmap_1. Notice that although bitmap_2 evaluates as being equal to bitmap_1, clonedBitmap does not, even though it contains the same values as bitmap_1.
import flash.display.BitmapData;
var bitmap_1:BitmapData = new BitmapData(100, 80, false, 0x000000);
var bitmap_2:BitmapData = bitmap_1;
var clonedBitmap:BitmapData = bitmap_1.clone();
trace(bitmap_1 == bitmap_2); // true
trace(bitmap_1 == clonedBitmap); // false
for(var i in bitmap_1) {
trace(">> " + i + ": " + bitmap_1[i]);
// >> generateFilterRect: [type Function]
// >> dispose: [type Function]
// >> clone: [type Function]
// >> copyChannel: [type Function]
// >> noise: [type Function]
// >> merge: [type Function]
// >> paletteMap: [type Function]
// >> hitTest: [type Function]
// >> colorTransform: [type Function]
// >> perlinNoise: [type Function]
// >> getColorBoundsRect: [type Function]
// >> floodFill: [type Function]
// >> setPixel32: [type Function]
// >> getPixel32: [type Function]
// >> pixelDissolve: [type Function]
// >> draw: [type Function]
// >> threshold: [type Function]
// >> scroll: [type Function]
// >> applyFilter: [type Function]
// >> copyPixels: [type Function]
// >> fillRect: [type Function]
// >> setPixel: [type Function]
// >> getPixel: [type Function]
// >> transparent: false
// >> rectangle: (x=0, y=0, w=100, h=80)
// >> height: 80
// >> width: 100
}
for(var i in clonedBitmap) {
trace(">> " + i + ": " + clonedBitmap[i]);
// >> generateFilterRect: [type Function]
// >> dispose: [type Function]
// >> clone: [type Function]
// >> copyChannel: [type Function]
// >> noise: [type Function]
// >> merge: [type Function]
// >> paletteMap: [type Function]
// >> hitTest: [type Function]
// >> colorTransform: [type Function]
// >> perlinNoise: [type Function]
// >> getColorBoundsRect: [type Function]
// >> floodFill: [type Function]
// >> setPixel32: [type Function]
// >> getPixel32: [type Function]
// >> pixelDissolve: [type Function]
// >> draw: [type Function]
// >> threshold: [type Function]
// >> scroll: [type Function]
// >> applyFilter: [type Function]
// >> copyPixels: [type Function]
// >> fillRect: [type Function]
// >> setPixel: [type Function]
// >> getPixel: [type Function]
// >> transparent: false
// >> rectangle: (x=0, y=0, w=100, h=80)
// >> height: 80
// >> width: 100
}
To further demonstrate the relationships between bitmap_1, bitmap_2, and clonedBitmap the following example modifies the pixel value at (1, 1) of bitmap_1. Modifying pixel value at (1, 1) demonstrates that the clone() method creates an instance based on values of the bitmap_1 instance instead instead of refering to the values.
import flash.display.BitmapData; var bitmap_1:BitmapData = new BitmapData(100, 80, false, 0x000000); var bitmap_2:BitmapData = bitmap_1; var clonedBitmap:BitmapData = bitmap_1.clone(); trace(bitmap_1.getPixel32(1, 1)); // -16777216 trace(bitmap_2.getPixel32(1, 1)); // -16777216 trace(clonedBitmap.getPixel32(1, 1)); // -16777216 bitmap_1.setPixel32(1, 1, 0xFFFFFF); trace(bitmap_1.getPixel32(1, 1)); // -1 trace(bitmap_2.getPixel32(1, 1)); // -1 trace(clonedBitmap.getPixel32(1, 1)); // -16777216
Version 8
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/8/main/00001945.html