ExpatTech is closed for the holidays from December 22nd to January 1st. We will open again on Wednesday January the 2nd. Happy Holidays!

ExpatTech Techblog

Peter Todd 2010.10.01. 09:01

Flash Cookbook - Colors - Part 2. Invert Displayobject's Colors

To invert the colors of a displayobject you can use the transform.colorTransform property of the displayobject and apply a ColorTransform to it.

The ColorTransform object you will use in this battle is:

var colortransform:ColorTransform = new ColorTransform(-1, -1, -1, 1, 255, 255, 255, 0);

To put it in a handy little function:

static public function invert(object:DisplayObject = null):ColorTransform
{
    if(object != null) object.transform.colorTransform = new ColorTransform(-1, -1, -1, 1, 255, 255, 255, 0);
    
    return new ColorTransform(-1, -1, -1, 1, 255, 255, 255, 0);
}