clone (BitmapData.clone メソッド)

public clone() : BitmapData

新しい BitmapData オブジェクトとして、元のインスタンスのクローンを返します。含まれるビットマップはまったく同じコピーになります。

対応バージョン : ActionScript 1.0、Flash Player 8

戻り値

BitmapData - 元のオブジェクトと同一の新しい BitmapData オブジェクト。

次の例では、3 つの BitmapData オブジェクトを作成し、それらを比較します。BitmapData コンストラクタを使用することにより、bitmap_1 インスタンスを作成します。bitmap_1 と等しくなるよう bitmap_2 インスタンスを作成します。bitmap_1 のクローンを作成することにより、clonedBitmap インスタンスを作成します。bitmap_2bitmap_1 と等しいと評価される場合に、たとえ bitmap_1 と同じ値を含んでいても clonedBitmap は等しいと評価されないことに注意してください。

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
}

bitmap_1bitmap_2、および clonedBitmap 間の関係をさらに詳しく示すため、次の例では bitmap_1 の (1, 1) のピクセル値を変更します。(1, 1) のピクセル値を変更すると、clone() メソッドは値を参照する代わりに、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.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

 

このページに新しいコメントが追加された場合に、電子メールでの通知を希望する。 | コメントレポート

現在のページ: http://livedocs.adobe.com/flash/9.0_jp/main/00001396.html