Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : Smoother color change


thejokerman05
2/2/2006 10:41:10 PM
I would like to fade my buttons from black to grey when onRollOver. Since I'm
gonna use this in a Class for my buttons I dont think I can use the
"lmc_tween.as" functions. I must use the colorTransform to get it working. My
question is if I can get the colorTransform to change the color a little bit
smoother? Just like if I use the .colorTo method. Here's my code;



import flash.geom.ColorTransform;
import flash.geom.Transform;

var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(btn);
trans.colorTransform = colorTrans;

btn1.onRollOver = function() {
colorTrans.rgb = 0xBFBFBF;
trans.colorTransform = colorTrans;
kglad
2/5/2006 5:16:58 PM
the code below the dotted line adds a new method to movieclips ( colorFadeF() )
that allows you to transform any movieclip from color rgb1 and alpha a1 to
color rgb2 and alpha a2 in speed seconds using n steps:

anyMovieClip.colorFadeF(rgb1, a1, rgb2, a2, speed, n);

----------------------------------------------------------------
MovieClip.prototype.colorFadeF = function(rgb1, a1, rgb2, a2, speed, steps) {
if (!var314159) {
var314159 = 1;
trA = ;
}
function fadeF(mc) {
if (!mc.repeatPass) {
mc.repeatPass = 1;
}
co = mc.mcCO;
tf2 = mc.tf2;
tf1 = mc.tf1;
steps = mc.steps;
intermediateTF = mc.intermediateTF;
for (var ivar = 0; ivar<trA.length; ivar++) {
num = Math.floor(mc.repeatPass*(tf2]-tf1])/steps)+tf1];
intermediateTF] = num.toString();
}
co.setTransform(intermediateTF);
mc.repeatPass++;
if (mc.repeatPass>steps) {
clearInterval(mc.int);
}
updateAfterEvent();
}
this.mcCO = new Color(this);
this.mcCO.setRGB(rgb2);
this._alpha = a2;
this.tf2 = this.mcCO.getTransform();
this.mcCO.setRGB(rgb1);
this._alpha = a1;
this.tf1 = this.mcCO.getTransform();
this.steps = steps;
this.speed = speed;
this.intermediateTF = new Array();
clearInterval(this.int);
this.repeatPass=0;
this.int = setInterval(fadeF, 1000*this.speed/this.steps, this);
};
thejokerman05
2/5/2006 9:21:35 PM
AddThis Social Bookmark Button