Does AS3 have no color/rgba support class?
Easy as it is wo开发者_如何学Pythonrking with RGBA from a 32-bit value, most libraries I've used previously implement utilities to avoid all the bit-shifting, like an RGBA()
macro or similar. I can't see anything like this on livedocs, perhaps it's there and I am missing it?
Using Flash 9/10, it needs to be a core AS3 class.
AS3 don't have such thing. Well there might be class out there.
The simplest way:
var d:BitmapData = new BitmapData(10,10);
var pixel:int = d.getPixel(5,5);
var red:int = pixel >> 16;
var green:int = pixel >> 8 & 0xff;
var blue:int = pixel & 0xff;
Here I created a BitmapData. Then get the color of point(5,5). The pixel here is RGB. Then do some shifting to get component.
For a ARGB value(Edited):
var argb:int = 0x11223344;
var alpha:int = argb >> 24;
var red:int = argb >> 16 & 0xff;
var green:int = argb >> 8 & 0xff;
var blue:int = argb & 0xff;
Nope, there are no particular built-in methods to avoid bit-shifting. If you don't want to use a library, you could copy and paste some suitable functions into your code - google popped this up, and it looks suitable enough.
精彩评论