Sunday, February 14, 2010

The Colors!



Large version.

This is a result of me learning a bit about adjusting the color of a movie clip via actionscript. It was surprisingly very easy! Here's a quick trimmed down version of it. Keep in mind, this is contained within the onLoad function of a the colored panel's Class file.

var colorful = new Color(this);
var colorTransform = new Object();
colorful.setRGB(0x003366);
colorTransform = {ra:Math.random() * 100, rb:'0', ga:Math.random() * 100, gb:'0', ba:Math.random() * 100, bb:'0', aa:'100', ab:'100'};
colorful.setTransform(colorTransform);


The first line sets up a Color object and assigns it "this", or whatever movie clip you want it to adhere to. After that, we create an Object called "colorTransform" which will contain all the information for the actual color transformation. That information includes, as you can see, a long list of parameters such as "ra" and "ba". It seems like a long list, but there are essentially two types of parameters that relate to the red channel, green channel, blue channel, and alpha channel. The three I'm dealing with here are the ra, ga, and ba parameters which is a number from -100 to 100 and controls the percentage of that parameter's color. So, something like ra:100, ga:50, and ba:50 would yield a pinkish color.

Once we've set up what the colorTransform IS, we simply set it to our original Color object. Simple, eh? You can experiment a ton with it and even set up color tweens with this.

Bonus! You can use this on photos, too! Just be sure to set the imported picture to be cached as a Bitmap and the above code will work on it.

Enjoy!

No comments:

Post a Comment