Robusto's solution is too slow.
Since the RGB values are stored as follows:
8b Red | 8b Green | 8b Blue
And the value 0-255 (this is not a coincidence) also has 8b, you can use left bitwise shifts to get the value int, and THEN you can get the hex (almost 3 times faster). So:
var intVal:int = red << 16 | green << 8 | blue;
var hexVal:String = intVal.toString(16);
hexVal = "#" + (hexVal.length < 6 ? "0" + hexVal : hexVal);
Where are the red, green, and blue RGB values that you want to convert.
source
share