say you have a movieclip on stage, a yellow circle with instance name - ball
using this code, you can change the color to red
Code:
Color.prototype.setTint = function (r, g, b, amount) {
var trans = new Object ();
trans.ra = trans.ga = trans.ba = 100 - amount;
var ratio = amount / 100;
trans.rb = r * ratio;
trans.gb = g * ratio;
trans.bb = b * ratio;
this.setTransform (trans);
};
myColor = new Color (_root.ball);
myColor.setTint (255, 0, 0, 100);
you can cut the code into a tint.as file and load it with -
Code:
// Flash -
#include "tint.as"
//tint.as -
Color.prototype.setTint = function (r, g, b, amount) {
var trans = new Object ();
trans.ra = trans.ga = trans.ba = 100 - amount;
var ratio = amount / 100;
trans.rb = r * ratio;
trans.gb = g * ratio;
trans.bb = b * ratio;
this.setTransform (trans);
};
function applyTintOverTime (r, g, b, amount, steps) {
var counter = 0;
var increase = amount / steps;
amount = increase;
_root.onEnterFrame = function () {
if (counter >= steps) {
delete this.onEnterFrame;
} else {
myColor.setTint (r, g, b, increase);
increase += amount;
counter++;
}
};
}
myColor = new Color (_root.ball);
applyTintOverTime (255, 0, 255, 100, 20);
// the first three numbers are RGB values,
// then tint value, then no. of frames
this will fade the color gradually
hth