import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextFormat;
var myBitmapData:BitmapData;
var myBitmap:Bitmap;
var color:uint;
var colorStr:String;
GetColor(mc);
//a.scaleX = a.scaleY = 2;
/*a.x = 39.4;
a.y = 148;*/
addEventListener(MouseEvent.MOUSE_DOWN,down_fc);
this.stage.addEventListener(MouseEvent.CLICK,onClickHandler);
function down_fc(e:MouseEvent)
{
_txt.text = colorStr;
var text_format:TextFormat = new TextFormat();
text_format.color = colorStr;
_txt.setTextFormat(text_format);
}
function GetColor(mm:MovieClip)
{
myBitmapData = new BitmapData(mm.width,mm.height,false,0xFFFFFF);
trace(mm.width+" "+mm.height);
myBitmapData.draw(mm);
myBitmap = new Bitmap(myBitmapData);
myBitmap.x=39.4;
myBitmap.y=148;
addEventListener(MouseEvent.MOUSE_DOWN,mouseD_fc);
return myBitmap;
}
function mouseD_fc(e:MouseEvent)
{
color = myBitmapData.getPixel(e.localX,e.localY);
var temp_color:String = color.toString(16);
var temp_length:int = temp_color.length;
if (temp_length < 6)
{
switch (temp_length)
{
case 4 :
colorStr = "0x00" + color.toString(16);
break;
case 5 :
colorStr = "0x0" + color.toString(16);
break;
default :
trace("no case tested true");
}
}
else
{
colorStr=("0x"+color.toString(16)+"00000").slice(0,8);
trace(colorStr+"222222222222222");
}
}
function onClickHandler(e:MouseEvent):void
{
trace(colorStr+"~~~~~~~~~~~~"+"44444444444444");
}
我是写在帧上的 大家用的时候 随便找一个图 一个画text 试试看就知道怎么用了~