« Total Training for Adobe Flash CS3 Professional ActionScript 3 Essentials
» New Flex Builder pricing

ActionScript

Retrieving channels from a 32-bit color

Andrei Ionescu | 24.10.07 | 2 Comments

To isolate the color channels and alpha channel from a 32-bit color we use shifting and bitwise AND operator.

var colorValue:uint = 0xFFFFCC99;
 
// Isolate Alpha channel
var alpha:uint = ( colorValue << 24 ) & 0xFF;
// Isolate Red channel
var red:uint = ( colorValue << 16 ) & 0xFF;
// Isolate Green channel
var green:uint = ( colorValue << 8 ) & 0xFF;
// Isolate Blue channel
var blue:uint = colorValue & 0xFF;

To clear just one channel (let say red) in a 32-bit color value you can do as below:

// Clearing the red channel
colorValue &= 0xFF00FFFF;

Form more about this see Essential Actionscript 3.0 by Colin Moock, O’Reilly, chapter 26 - Bitmap Programming.

Share and Enjoy:
  • Technorati
  • StumbleUpon
  • del.icio.us
  • NewsVine
  • Reddit
  • Digg
  • Furl
  • co.mments
  • blogmarks
  • Slashdot
  • description
  • Taggly
  • YahooMyWeb
  • connotea
  • Webride




Tags: , , , , ,

This post was written by Andrei Ionescu

Views: 709

related

2 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">

:

:


« Total Training for Adobe Flash CS3 Professional ActionScript 3 Essentials
» New Flex Builder pricing