Mega Code Archive

 
Categories / Flash ActionScript / Graphics
 

To retrieve the value of a single channel from a 32-bit color value, we can use the right shift and bitwise AND operators togethe

package{   import flash.display.Sprite;      public class Main extends Sprite{     public function Main(){         var colorValue:uint   = 0xFFFFCC99;  // A sample color         var alpha:uint = (colorValue >> 24) & 0xFF;  // Isolate the Alpha channel         var red:uint   = (colorValue >> 16) & 0xFF;  // Isolate the Red channel         var green:uint = (colorValue >> 8) & 0xFF;   // Isolate the Green channel         var blue:uint  = colorValue & 0xFF;          // Isolate the Blue channel                  trace(alpha, red, green, blue);  // Displays: 255 255 204 153          }   } }