说明:点击对象是mc,将mc变成bitmapData对象,然后取色。
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;
}
演示效果:
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/4396.html
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;
}
演示效果:
本文转自:http://www.5uflash.com/flashjiaocheng/Flash-as3-jiaocheng/4396.html