2010年12月10日 星期五

[AS3] 由Bitmap類別實體的bitmapData屬性參照BitmapData物件,以其fillRect()方法在點陣像素上繪製矩形填色

BitmapData()建構函式
public function BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)
BitmapData.fillRect()方法public function fillRect(rect:Rectangle, color:uint):void
Rectangle()建構函式
public function Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0)


991210_BitmapData_fillRect_1.swf



//
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;

//
//BitmapData()建構函式
//public function BitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF)
var bmpData:BitmapData = new BitmapData(420, 320, true, 0xff6600ff);
var bitmap:Bitmap = new Bitmap(bmpData);
bitmap.x = 50;
bitmap.y = 50;
addChild(bitmap);

//
//Rectangle()建構函式
//public function Rectangle(x:Number = 0, y:Number = 0, width:Number = 0, height:Number = 0)
var rect1:Rectangle = new Rectangle(50, 120 ,20, 20);
for(var i:int=0; i<7; i++){
 //fillRect()方法  
 //public function fillRect(rect:Rectangle, color:uint):void
 //由Bitmap類別實體的bitmapData屬性參照BitmapData物件,
 //以其fillRect()方法在點陣像素上繪製矩形填色
 bitmap.bitmapData.fillRect(rect1, 0xffffffff);
 rect1.x += 20;
 rect1.y += 20;
}
//
var rect2:Rectangle = new Rectangle(170, 240 ,20, 20);
for(var j:int=0; j<12; j++){
 bitmap.bitmapData.fillRect(rect2, 0xffffffff);
 rect2.x += 20;
 rect2.y -= 20;
}

沒有留言: