Simple Hex Color Changer w/ ColorTransform – taterboy
August 6th, 2008 | Filed under: Flash AS2 to AS3, Tips
I was first introduced to the ColorTransform class while reading the AS2 to AS3 migration documentation about setRGB(). I was immediately impressed with the features, but intimidated when I saw the constructor and all the offset, color and alpha arguments. I just needed to change the color of something, nothing special, no gradients, no alpha, no space shuttle landings, just a simple hex color change.
So here is a simple color change utility that is a lot closer to what I am used to.
function paint(obj:Object,color:Number):void{
var ct:ColorTransform = new ColorTransform();
ct.color = color;
obj.transform.colorTransform = ct;
} |
source here
|
RSS feed for comments on this post. TrackBack URL
How are you converting the hex with letters to a number?
Comment by April — December 16, 2008 @ 7:58 pm
The hex is stored as a string
var hexStr:String = “003399″;
When I use it with the paint method I convert it to a number like so.
var newColor:Number = Number(”0x” + hexStr); //0×003399
Comment by taterboy — December 16, 2008 @ 8:19 pm