【AS3代码】颜色拾取器
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
public class Main extends Sprite
{
var a:Sprite; //用来显示拾取颜色的小方块
var xin:BitmapData; //存放当前新绘制出来的颜色
public function Main():void
{
init();
}
private function init():void
{
//Pic是一张背景图类,在flash cs4中已经转换为swc
var tu:Pic = new Pic(1,1);
var tut:Bitmap = new Bitmap(tu);
this.addChild(tut);
a = new Sprite();
a.graphics.beginFill(0x00ff00);
a.graphics.drawRect(0,0,50,50);
a.graphics.endFill();
this.addChild(a);
//xin是用来存放当前新绘制出来的舞台颜色
xin = new BitmapData(1,1,false,0x0);
stage.addEventListener(MouseEvent.MOUSE_MOVE, qu);
}
//用鼠标取颜色
private function qu(evt:MouseEvent):void
{
xin.draw(stage, new Matrix(1,0,0,1,-mouseX,-mouseY));
var mycolor:ColorTransform = new ColorTransform(); //存储color属性
mycolor.color = xin.getPixel(0,0);
a.transform.colorTransform = mycolor;
}
}
}