The new ColorMatrixFilter in Flash 8 provides enhanced color manipulation capabilities to developers. If you've played around with it, you've noticed that the ColorMatrixFilter accepts a 5x4 matrix (20 element Array in Flash) and uses specific indices in that array as multiplication values for Red, Green, Blue and Alpha, as well as offset values (we are currently writing an article explaining different types of matrices in depth, including the ColorMatrix, which you should see at Macromedia's Developer Center in the near future). The ColorMatrix class was born a while back out of the need to have a more "friendly" programmatic interface to manipulating these color values.

ColorMatrix provides a way to adjust Brightness, Contrast, Saturation and Hue based on a range of numeric values as well as multiply matrices. The ColorMatrix can then be passed into ColorMatrixFilter to apply color adjustments. The added bonus of ColorMatrix is that it uses the same calculations to generate matrix values as the Flash 8 IDE (with the exception of contrast adjustment which uses linear interpolation to provide a bit more granularity).

Here is an example which uses ColorMatrix to adjust colors together with the MultiTween class to tween ColorMatrix values using 2 different types of tweens.

You can download the source here.




In writing this entry, I also noticed that the ever wise Quasimondo has written his own ColorMatrix class. Cheers :)