/** * VERSION: 1.7 * DATE: 2011-09-15 * AS2 * UPDATES AND MORE DOCS AT: http://www.greensock.com **/ import com.greensock.*; import com.greensock.plugins.*; /** * Ever wanted to tween ColorTransform properties of a MovieClip to do advanced effects like overexposing, altering * the brightness or setting the percent/amount of tint? Or maybe tween individual ColorTransform * properties like redMultiplier, redOffset, blueMultiplier, blueOffset, etc. ColorTransformPlugin gives you an easy way to * do just that.

* * PROPERTIES:
*

* * USAGE:

* * import com.greensock.TweenLite;
* import com.greensock.plugins.TweenPlugin;
* import com.greensock.plugins.ColorTransformPlugin;
* TweenPlugin.activate([ColorTransformPlugin]); //activation is permanent in the SWF, so this line only needs to be run once.

* * TweenLite.to(mc, 1, {colorTransform:{tint:0xFF0000, tintAmount:0.5}});

*
* * Copyright 2011, GreenSock. All rights reserved. This work is subject to the terms in http://www.greensock.com/terms_of_use.html or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership. * * @author Jack Doyle, jack@greensock.com */ class com.greensock.plugins.ColorTransformPlugin extends TintPlugin { /** @private **/ public static var API:Number = 1.0; //If the API/Framework for plugins changes in the future, this number helps determine compatibility /** @private **/ public function ColorTransformPlugin() { super(); this.propName = "colorTransform"; } /** @private **/ public function onInitTween(target:Object, value:Object, tween:TweenLite):Boolean { if (typeof(target) != "movieclip" && !(target instanceof TextField)) { return false; } var color:Color = new Color(target); var end:Object = color.getTransform(); if (value.redMultiplier != undefined) { end.ra = value.redMultiplier * 100; } if (value.greenMultiplier != undefined) { end.ga = value.greenMultiplier * 100; } if (value.blueMultiplier != undefined) { end.ba = value.blueMultiplier * 100; } if (value.alphaMultiplier != undefined) { end.aa = value.alphaMultiplier * 100; } if (value.redOffset != undefined) { end.rb = value.redOffset; } if (value.greenOffset != undefined) { end.gb = value.greenOffset; } if (value.blueOffset != undefined) { end.bb = value.blueOffset; } if (value.alphaOffset != undefined) { end.ab = value.alphaOffset; } if (!isNaN(value.tint) || !isNaN(value.color)) { var tint:Object = (!isNaN(value.tint)) ? value.tint : value.color; //make it an object so that it can be null (Numbers can't) if (tint != null) { /* to clear the ColorTransform (make it return to normal), use this... var alpha:Number = target._alpha; end.rb = 0; end.gb = 0; end.bb = 0; end.ra = alpha; end.ga = alpha; end.ba = alpha; end.aa = alpha; */ end.rb = (Number(tint) >> 16); end.gb = (Number(tint) >> 8) & 0xff; end.bb = (Number(tint) & 0xff); end.ra = 0; end.ga = 0; end.ba = 0; } } if (!isNaN(value.tintAmount)) { var ratio:Number = value.tintAmount / (1 - ((end.ra + end.ga + end.ba) / 300)); end.rb *= ratio; end.gb *= ratio; end.bb *= ratio; end.ra = end.ga = end.ba = (1 - value.tintAmount) * 100; } else if (!isNaN(value.exposure)) { end.rb = end.gb = end.bb = 255 * (value.exposure - 1); end.ra = end.ga = end.ba = 100; } else if (!isNaN(value.brightness)) { end.rb = end.gb = end.bb = Math.max(0, (value.brightness - 1) * 255); end.ra = end.ga = end.ba = (1 - Math.abs(value.brightness - 1)) * 100; } if (tween.vars._alpha != undefined && value.alphaMultiplier == undefined) { end.aa = tween.vars._alpha; tween.killVars({_alpha:1}); } init(target, end); return true; } }