Flash / Flex / ActionScript/Graphics/Color

Материал из Web эксперт
Перейти к: навигация, поиск

Produces a number that is the effective result of inserting the hex value AA into an existing color value

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var colorValue:uint   = 0xFFFFCC99;  // A sample color
        colorValue &= 0xFF00FFFF;
        colorValue |= (0xAA<<16);
        trace(colorValue.toString(16));  // Displays: ffaacc99
    }
  }
}



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

 
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
    
    }
  }
}