Please note that ExpatTech is close for the Christmas and New Year holidays. We will re-open on 2nd January 2024.

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);
}