|
Onto Flash now. After a lot of searching and dead ends (And flash CS3 docs giving code for AS2!) i finally figured out an easy way to tween brightness of an object. As this uses the Colour (Color) matrix transformations this also applied to colour tweening.
The Method:
Perform a tween on a new object, and set it to tween an arbitrary property. Set the easing and brightnes values (between 0 for dark and 255 for light), and timings as needed. Then add a listener for TweenEvent.MOTION_CHANGE. Within this event we build a brightness colour matrix using the current tween position and apply to the mc.filters array!
The Code:
import fl.transitions.Tween; import fl.transitions.TweenEvent; import fl.transitions.easing.*; import flash.filters.ColorMatrixFilter;
var tw:Tween = new Tween(new Object(),"x",None.easeNone,200,0,5,true); tw.addEventListener(TweenEvent.MOTION_CHANGE, function(e:TweenEvent):void { var val:Number = e.position; var brightness_array:Array = [1, 0, 0, 0, val, 0, 1, 0, 0, val, 0, 0, 1, 0, val, 0, 0, 0, 1, 0]; mc.filters = [new ColorMatrixFilter(brightness_array)]; });
I hope this helps someone out there!
Cheers, James
|