2010年12月23日 星期四

[AS3] ColorMatrixFilter.clone()方法 - 傳回此濾鏡物件的副本

ColorMatrixFilter.clone();
clone():BitmapFilter - clone()方法傳回值為BitmapFilter物件
[覆寫] 傳回此濾鏡物件的副本。

● 點擊[click]按鈕,拷貝左圖的ColorMatrixFilter物件,到右圖套用同樣濾境效果。

991223_ColorMatrixFilter.clone_1.swf



package  {
 import flash.display.Sprite;
 import flash.filters.ColorMatrixFilter;
 import flash.display.BitmapData;
 import flash.display.Bitmap;
 import flash.filters.BitmapFilter;
 import flash.display.DisplayObject;
 import flash.events.Event;
 import flash.events.MouseEvent;

 //
 public class ColorMatrixFilter_clone_991223_1 extends Sprite{
  //
  public var bmd1:BitmapData = new MyPhoto1(0,0);
  public var bm1:Bitmap = new Bitmap(bmd1);
  public var bmd2:BitmapData = new MyPhoto2(0,0);
  public var bm2:Bitmap = new Bitmap(bmd2);
  //
  public var myFilter1:ColorMatrixFilter;
  //
  public function ColorMatrixFilter_clone_991223_1() {
   addChild(bm1);
   addChild(bm2);
   addChild(click_mc);
   with(bm1){
    scaleX = 0.4;
    scaleY = 0.4;
    x = 40;
    y = 50;
   }
   with(bm2){
    scaleX = 0.4;
    scaleY = 0.4;
    x = 290;
    y = 50;
   }
   
   firstMat();
   click_mc.addEventListener(MouseEvent.CLICK, cloneMat);
   click_mc.buttonMode = true;
  }
  //
  public function firstMat():void{
   var matrix1:Array = new Array();
   matrix1 = matrix1.concat([0, 0, 1.5, 0, 0]); //RED Channel
   matrix1 = matrix1.concat([0, 1.5, 0, 0, 0]); //GREEN Channel
   matrix1 = matrix1.concat([1.5, 0, 0, 0, 0]); //BLUE Channel
   matrix1 = matrix1.concat([0, 0, 0, 1, 0]); //ALPHA Channel
   myFilter1 = new ColorMatrixFilter(matrix1);
   bm1.filters = [myFilter1]; 
  }
  //
  public function cloneMat(e:Event = null){
   //ColorMatrixFilter.clone();
   //clone():BitmapFilter - clone()方法傳回值為BitmapFilter物件
   //[覆寫] 傳回此濾鏡物件的副本。
   var myFilter2:BitmapFilter = myFilter1.clone();
   bm2.filters = [myFilter2];
  }

 }
 
 
}

沒有留言: