package flashAs {
 import flash.display.BitmapData;
 import flash.geom.Matrix;
 //具有圖片反轉功能的類別
 public class ImageRotation extends Sprite{
  private var matrix:Matrix;
  private var sourceBD:BitmapData;
  //建構子, 設定圖片來源和座標
  public function ImageRotation (BD:BitmapData, X:int, Y:int){
   sourceBD= BD;
   this.x = X;    this.y = Y; 
   //--設定變型矩陣的物件
   matrix = new Matrix();
   matrix.a=-1;
   matrix.b =  Math.sin( (180/180) * Math.PI);
   matrix.tx= sourceBD.width;
   this. goRecovery();
  }
  //進行水平反轉
  public function goRotation (){
   this.graphics.clear();
   this.graphics.beginBitmapFill(sourceBD, matrix, false);
   this.graphics.drawRect(0, 0, sourceBD.width, sourceBD.height);
   this.graphics.endFill();
  }
  //恢復原始圖片
  public function goRecovery(){
   this.graphics.clear();
   this.graphics.beginBitmapFill(sourceBD);
   this.graphics.drawRect(0, 0, sourceBD.width, sourceBD.height);
  }
 }
}
沒有留言:
張貼留言