class:
/*-----design by whb 2008-8-21-----
构造函数的参数pic:放置图片的mc
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class GetColor extends Sprite {
private var myBitmapData:BitmapData;
private var myBitmap:Bitmap;
private var color:uint;
public var colorStr:String;
public function GetColor(mc:MovieClip) {
myBitmapData=new BitmapData(mc.width,mc.height,true,0xffffff);
myBitmapData.draw(mc);
myBitmap=new Bitmap(myBitmapData);
addChild(myBitmap);
addEventListener(MouseEvent.MOUSE_DOWN,mouseD_fc);
}
private function mouseD_fc(e:MouseEvent) {
color=myBitmapData.getPixel(e.localX,e.localY);
colorStr=("0x"+color.toString(16)+"00000").slice(0,8);
}
}
}
as:
import GetColor;
var mymc:mc=new mc();
var a:GetColor=new GetColor(mymc);
a.scaleX=a.scaleY=2;
a.x=100;
a.y=100;
addChild(a);
addEventListener(MouseEvent.MOUSE_DOWN,down_fc);
function down_fc(e:MouseEvent){
_txt.text=a.colorStr;
}
--------------------next---------------------
阅读(352) | 评论(0) | 转发(0) |