color_toolkit.as

来自「这是《Flash MX编程与创意实现》的源代码」· AS 代码 · 共 621 行 · 第 1/2 页

AS
621
字号
};


// ====== tint - MovieClip methods ======

// tint with a color just like Property Inspector
// r, g, b between 0 and 255; percent between 0 and 100
MovieClip.prototype.setTint = function (r, g, b, percent) {
	(new Color(this)).setTint (r, g, b, percent);
};

// returns a tint object containing r, g, b, and percent properties
MovieClip.prototype.getTint = function () {
	return (new Color(this)).getTint();
};

// tint with a color - alternate approach
// rgb a color number between 0 and 0xFFFFFF; percent between 0 and 100
MovieClip.prototype.setTint2 = function (rgb, percent) {
	(new Color(this)).setTint2 (rgb, percent);
};

// returns a tint object containing rgb (a 0xFFFFFF number) and percent properties
MovieClip.prototype.getTint2 = function () {
	return (new Color(this)).getTint2();
};

// --------------------------------------------------------
// ====== tint offset - Color methods ======

// r, g, b between -255 and 255
Color.prototype.setTintOffset = function (r, g, b) {
	var trans = this.getTransform();
	with (trans) { rb = r; gb = g; bb = b; }
	this.setTransform (trans);
};

Color.prototype.getTintOffset = function () {
	var t = this.getTransform();
	return {r:t.rb, g:t.gb, b:t.bb};
};

// ====== tint offset - MovieClip methods ======

// r, g, b between -255 and 255
MovieClip.prototype.setTintOffset = function (r, g, b) {
	(new Color(this)).setTintOffset (r, g, b, percent);
};

// returns a tint offset object containing r, g, and b properties
MovieClip.prototype.getTintOffset = function () {
	return (new Color(this)).getTintOffset();
};


// --------------------------------------------------------
// ====== color inversion - Color methods ======

// invert the current color values
Color.prototype.invert = function () {
	var trans = this.getTransform();
	with (trans) {
		ra = -ra;
		ga = -ga;
		ba = -ba;
		rb = 255 - rb;
		gb = 255 - gb;
		bb = 255 - bb;
	}
	this.setTransform (trans);
}; 

// produce a negative image of the normal appearance
Color.prototype.setNegative = function (percent) {
    var t = {};
    t.ra = t.ga = t.ba = 100 - 2 * percent;
    t.rb = t.gb = t.bb = percent * (255/100);
    this.setTransform (t);
};

Color.prototype.getNegative = function () {
    return this.getTransform().rb * (100/255);
};


// ====== color inversion - MovieClip methods ======

// invert current color values
MovieClip.prototype.invertColor = function () {
	(new Color(this)).invert();
};

// produce a negative image of the normal appearance
MovieClip.prototype.setNegativeColor = function (percent) {
    (new Color(this)).setNegative (percent);
};

MovieClip.prototype.getNegativeColor = function () {
    return (new Color(this)).getNegative();
};


// --------------------------------------------------------
// ====== solid color - Color methods ======

Color.prototype.setRed = function (amount) {
	var t = this.getTransform();
	this.setRGB (amount << 16 | t.gb << 8 | t.bb);
};

Color.prototype.getRed = function () {
	return this.getTransform().rb;
};

Color.prototype.setGreen = function (amount) {
	var t = this.getTransform();
	this.setRGB (t.rb << 16 | amount << 8 | t.bb);
};

Color.prototype.getGreen = function () {
	return this.getTransform().gb;
};

Color.prototype.setBlue = function (amount) {
	var t = this.getTransform();
	this.setRGB (t.rb << 16 | t.gb << 8 | amount);
};

Color.prototype.getBlue = function () {
	return this.getTransform().bb;
};

// ====== solid color - MovieClip methods ======

MovieClip.prototype.setRed = function (percent) {
	(new Color(this)).setRed (percent);
};

MovieClip.prototype.getRed = function () {
	return (new Color(this)).getRed();
};

MovieClip.prototype.setGreen = function (percent) {
	(new Color(this)).setGreen (percent);
};

MovieClip.prototype.getGreen = function () {
	return (new Color(this)).getGreen();
};

MovieClip.prototype.setBlue = function (percent) {
	(new Color(this)).setBlue (percent);
};

MovieClip.prototype.getBlue = function () {
	return (new Color(this)).getBlue();
};


// --------------------------------------------------------
// ====== color percent - Color methods ======

Color.prototype.setRedPercent = function (percent) {
	var trans = this.getTransform();
	trans.ra = percent;
	this.setTransform (trans);
};

Color.prototype.getRedPercent = function () {
	return this.getTransform().ra;
};

Color.prototype.setGreenPercent = function (percent) {
	var trans = this.getTransform();
	trans.ga = percent;
	this.setTransform (trans);
};

Color.prototype.getGreenPercent = function () {
	return this.getTransform().ga;
};

Color.prototype.setBluePercent = function (percent) {
	var trans = this.getTransform();
	trans.ba = percent;
	this.setTransform (trans);
};

Color.prototype.getBluePercent = function () {
	return this.getTransform().ba;
};

// ====== color percent - MovieClip methods ======

MovieClip.prototype.setRedPercent = function (percent) {
	(new Color(this)).setRedPercent (percent);
};

MovieClip.prototype.getRedPercent = function () {
	return (new Color(this)).getRedPercent();
};

MovieClip.prototype.setGreenPercent = function (percent) {
	(new Color(this)).setGreenPercent (percent);
};


MovieClip.prototype.getGreenPercent = function () {
	return (new Color(this)).getGreenPercent();
};

MovieClip.prototype.setBluePercent = function (percent) {
	(new Color(this)).setBluePercent (percent);
};

MovieClip.prototype.getBluePercent = function () {
	return (new Color(this)).getBluePercent();
};


// --------------------------------------------------------
// ====== color offset - Color methods ======

Color.prototype.setRedOffset = function (offset) {
	var trans = this.getTransform();
	trans.rb = offset;
	this.setTransform (trans);
};

Color.prototype.getRedOffset = function () {
	return this.getTransform().rb;
};

Color.prototype.setGreenOffset = function (offset) {
	var trans = this.getTransform();
	trans.gb = offset;
	this.setTransform (trans);
};

Color.prototype.getGreenOffset = function () {
	return this.getTransform().gb;
};

Color.prototype.setBlueOffset = function (offset) {
	var trans = this.getTransform();
	trans.bb = offset;
	this.setTransform (trans);
};

Color.prototype.getBlueOffset = function () {
	return this.getTransform().bb;
};

// ====== color offset - MovieClip methods ======

MovieClip.prototype.setRedOffset = function (offset) {
	(new Color(this)).setRedOffset (offset);
};

MovieClip.prototype.getRedOffset = function () {
	return (new Color(this)).getRedOffset();
};

MovieClip.prototype.setGreenOffset = function (offset) {
	(new Color(this)).setGreenOffset (offset);
};


MovieClip.prototype.getGreenOffset = function () {
	return (new Color(this)).getGreenOffset();
};

MovieClip.prototype.setBlueOffset = function (offset) {
	(new Color(this)).setBlueOffset (offset);
};

MovieClip.prototype.getBlueOffset = function () {
	return (new Color(this)).getBlueOffset();
};



// --------------------------------------------------------

// create MovieClip color properties
// associate getter/setter methods with property names
with (MovieClip.prototype) {
	addProperty ("_brightness", getBrightness, setBrightness);
	addProperty ("_brightOffset", getBrightOffset, setBrightOffset);
	addProperty ("_negativeColor", getNegativeColor, setNegativeColor);
	addProperty ("_rgb", getRGB, setRGB);
	addProperty ("_red", getRed, setRed);
	addProperty ("_green", getGreen, setGreen);
	addProperty ("_blue", getBlue, setBlue);
	addProperty ("_redPercent", getRedPercent, setRedPercent);
	addProperty ("_greenPercent", getGreenPercent, setGreenPercent);
	addProperty ("_bluePercent", getBluePercent, setBluePercent);
	addProperty ("_redOffset", getRed, setRedOffset);
	addProperty ("_greenOffset", getGreen, setGreenOffset);
	addProperty ("_blueOffset", getBlue, setBlueOffset);
}


// hide stuff from for..in loops
ASSetPropFlags (MovieClip.prototype, null, 1);

trace ("-- Color Toolkit loaded --");


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?