点击取色

//说明:点击对象是mc,将mc变成bitmapData对象,然后取色。
//class: 
//构造函数的参数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;
}
posted @ 2011-03-08 19:00  sinsoul  阅读(314)  评论(0编辑  收藏  举报