/ Uncategorized

Color Transitions with Flash

I recently wanted to tween a movie clip in Flash from one Color to another. I discovered that the current transition classes by Flash don't support tweening properties apart from the alpha channel, position or size.

I had two options: Either write the classes myself or hope that somebody else did write them already. Of course I didn't have to invent the wheel twice.

I downloaded the Caurina Tweener Class hosted at Google Code. http://code.google.com/p/tweener/

This problem would have cost me to write 50 to 100 lines of code at least. I would have to convert Hex to RGB values and calculate color multipliers and apply every new resulting color one by one to a unique frame via transform.ColorTransform();

With tweener it's a simple one-liner:

Tweener.addTween(myMovieClipName, {_color: 0xc5ce8a, time:1, transition:"easeOut"});

That underscore before _color is not just another depreciated AS2 property, but it is from Tweener's classes and you have to use it in AS3.

As the more advanced ActionScripter might has noticed, Tweener is a static class and you can't instantiate any objects from it, but you can tell Tweener what to do with your own objects and any of its properties. The resulting motion tween doesn't have to be a linear movement. Tweener is better than that because you can apply Penner's Easing equations.

In my above example I used a simple accelerated movement called easeOut. It will create a accelerated motion between a given color and the color C5Ce8a.

This happens to be nice greenish tint.

Color Transitions with Flash
Share this