Increase Brightness / color tint of displayobject in AS3

The below code will make an object instance name ‘objectMC’ a bit brighter on mouse over, and back to normal on mouseOut. This uses colorTransform, see below and have a play with the values. You can also use ‘redMultiplier’ in tandem with ‘redOffset’ to create different effects, but just adding some to all 3 color channels makes the brightness higher.

import flash.events.MouseEvent;
//objectMC.addEventListener(MouseEvent.CLICK, onClickHandler):
objectMC.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverHandler);
objectMC.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutHandler);
objectMC.buttonMode = true;
function onClickHandler(event:MouseEvent):void
{
// do nothing right now.
}

// these two functions below are just to put a slight white tint on the item when rolled over
var offSetAmount:Number = 30;
var colorT:ColorTransform = new ColorTransform();

function onMouseOverHandler(event:MouseEvent):void
{
  colorT.blueOffset = offSetAmount;
  colorT.redOffset = offSetAmount;
  colorT.greenOffset = offSetAmount;
  event.target.transform.colorTransform = colorT;
}

function onMouseOutHandler(event:MouseEvent):void
{
  // back to normal
  colorT.blueOffset = 0;
  colorT.redOffset = 0;
  colorT.greenOffset = 0;
  event.target.transform.colorTransform = colorT;
}

Note:
It is much easier just to use TweenLite’s tint plugin for this.

import com.greensock.TweenLite;
import com.greensock.plugins.*;
TweenPlugin.activate([TintPlugin]);

TweenLite.to(targetMC, 0, {tint:0xFF0000});

// and back to nothing
TweenLite.to(targetMC, 0, {tint:null});
Tech Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑