In this class we will create some useful public static function to handle the color of a movieclip with the RGBColor Class. the class code is below so let's take a look.








Class

import com.core.RGBColor;</span></p>/**
*Class
* @author Amen Kamaleldine
*/
class com.core.BindColor {
 /**
  * Retrieve an RGBColor from a color number
  * @param color
  * @return
  */

 public static function colorToRGB(color:Number):RGBColor {
  var colorObj:Object = getRGB(color);
  return new RGBColor(colorObj.r,colorObj.g,getRGB.b );
 }
 /**
  * Retrieve an rgb object
  * @param color
  * @return Object
  */

 private static function getRGB(color:Number):Object {
  //Description
  // XX   XX    XX
  // red   green  blue
 
  //shift left by 16 bit( 4 x 4 ) the color to get the red value
  var r = color >> 16;
  //get the 00 XX XX no red
  var aux = color-(r << 16);
  //get the green by shifting 8 bit
  var g = aux >> 8;
  // and the blue by substracting the aux from the green value
  var b = aux - (g << 8);
 
  //Example
  /**
   * XXYYZZ
   * red is 0000XX
   * green is 0000YY
   * blue is 0000ZZ
   * first step is transforming XXYYZZ to 0000XX
   * the substracting  XX0000 from XXYYZZ
   * we ll have aux=00YYZZ
   * then shit 8 bit to the right
   * will got the green 0000YY
   * and for the blue is the 00YYZZ substract 00YY00
   */

 
  return ({r:r, g:g, b:b});
 }
 /**
  * gets an RGBColor Object from a movie Clip
  * @param mc
  * @return
  */

 public static function getRGBFrom(mc:MovieClip):RGBColor{
 
 
  var current_color = getColorFrom(mc);
 
  return colorToRGB(current_color);
 }
 /**
  * gets the color of a movieclip
  * @param mc
  * @return
  */

 public static function getColorFrom(mc:MovieClip):Number{
  var mc_color:Color = new Color(mc);
 
  var current_color=mc_color.getRGB();
 
  return current_color;
 }
 /**
  * bind an RGBColor to a movie clip
  * @param rgbColor
  * @param mc
  */

 public static function bindColorTo(rgbColor:RGBColor, mc:MovieClip):Void {
  var mc_color:Color = new Color(mc);
   
  var mc_colorTransform:Object = { ra: 0, rb: rgbColor.red, ga: 0, gb: rgbColor.green, ba: 0, bb: rgbColor.blue, aa: 100, ab: 0 };
   
  mc_color.setTransform(mc_colorTransform);
 }
 
}


So to bind an RGBColor to a movieclip we call BindColor.bindColorTo(RGBColor,MovieClip);

Lets examine how now we can animate the tint on the next page