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 2009.12.02. 14:40

Flash Cookbook - Colors - brightness of movieclip

Now we learn how to set the brightness of a movieclip. It's quite easy and it will be our first step into colormatrixfilter.

function setBrightness(target:MovieClip, value:Number = 0):void
{
    var element:Number = value;
    var matrix:Array = [1, 0, 0, 0, element,
            0, 1, 0, 0, element,
            0, 0, 1, 0, element,
            0, 0, 0, 1, 0];
    var colorfilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);

    target.filters = [colorfilter];
}

The colormatrix filter is constructed with a matrix. The value for brightness can go from -255 to 255.