PDA

View Full Version : two way color tween



davelk
September 26th, 2008, 09:38 AM
Hi, I have a movieclip and I would like to give it a smooth color animation from dark grey to blue when it is being hovered over and the reverse when you move the mouse out, like what you would expect from making a shape tween in the timeline and then use
nextFrame() and prevFrame() to make it smooth and responsive.

So far I can sharply change the color but I'm pretty stuck.

Any suggestions would be really appreciated



import fl.motion.Color;

var colorInfo:ColorTransform = item.transform.colorTransform;
item.addEventListener(MouseEvent.MOUSE_OVER, tweenToBlue);
function tweenToBlue(e:MouseEvent):void
{
colorInfo.color = Color.interpolateColor(0x333333, 0x0033CC, 1);
item.transform.colorTransform = colorInfo;
}

jwopitz
September 26th, 2008, 11:40 AM
I am not really an expert in color styles so this is an educated guess. I think you have a few options to say something like,

while (colorA < targetColor)
{
increase colorA by a certain amount
}

Do that within your function? Or you could actually use a tween type class and tween the values, giving it a current color and target color. Check out GTween by Grant Skinner. It is super lite weight to use.