// display object, red (0-255), green, blue, amount (0-1)
function tint(dsp:DisplayObject, r:Number, g:Number, b:Number, amount:Number=1):void {
if (amount != 1) {
r *= amount;
g *= amount;
b *= amount;
}
amount = 1-amount;
var ct:ColorTransform = transform.colorTransform;
ct.redOffset = r;
ct.redMultiplier = amount;
ct.greenOffset = g;
ct.greenMultiplier = amount;
ct.blueOffset = b;
ct.blueMultiplier = amount;
dsp.transform.colorTransform = ct;
}
// test out the tint function on a circle with a stroke:
var circle:Shape = Shape(addChild(new Shape()));
with (circle.graphics) {
lineStyle(5, 0x339999);
beginFill(0x003333);
drawCircle(0,0,50);
x = 100;
y = 100;
}
// tint the circle 50% green
tint(circle, 0, 255, 0, .5);
The ColorTransform object is a little confusing with its “redMultiplier, redOffset, greenMultiplier etc…” properties. Once you understand them it’s not a big deal, but I still find them a bit cumbersome. So when I just want to tint a clip similar to the way you might tint a clip in the IDE… I use this tint function. Rather than taking a hexidecimal number it takes values for red, green and blue (0-255) – and an amount argument (0-1).
Id say overall that Ive found ColorTransform to be rather useful.