Color.setTint() alternative (AS3)
I once discovered a really cool feature of the color class that lets you set the tint of an object via its color transform object using the setTint function.
The bad news though is that the Color class is in the fl namespace, so if you’re developing outside of the Flash IDE you have no access to that class natively, so here is how to replicate that functionality without the Color class:
Tinting with the color class:
import fl.motion.Color; // Tint the movie clip 50% with the color 0xFF9933 var c:Color = new Color(); c.setTint(0xFF9933, 0.5); myMovieClip.transform.colorTransform = c;
Tinting without the color class:
import flash.geom.ColorTransform; // Tint the movie clip 50% with the color 0xFF9933 var tintColor:uint = 0xFF9933; var tintMultiplier:Number = 0.5; setTint(myMovieClip, tintColor, tintMultiplier); function setTint(displayObject:DisplayObject, tintColor:uint, tintMultiplier:Number):void { var colTransform:ColorTransform = new ColorTransform(); colTransform.redMultiplier = colTransform.greenMultiplier = colTransform.blueMultiplier = 1-tintMultiplier; colTransform.redOffset = Math.round(((tintColor & 0xFF0000) >> 16) * tintMultiplier); colTransform.greenOffset = Math.round(((tintColor & 0x00FF00) >> 8) * tintMultiplier); colTransform.blueOffset = Math.round(((tintColor & 0x0000FF)) * tintMultiplier); displayObject.transform.colorTransform = colTransform; }
Tags: alternative, AS3, class, color, colortransform, multiplier, setTint, source, tint, transform
October 29th, 2010 at 15:07
cool man!!!!! i love it and i need it……..Thanks
December 2nd, 2010 at 01:26
Nice, exactly what i was looking for!
tested and working in FleshDevelop with FlexSDK
August 29th, 2014 at 14:11
thanks, that was what I needed !!!