Try this code:
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute“>
<mx:Script>
<![CDATA[
public function convertToRGB(drawColor:uint):String {
var r:String="";
var b:String="";
var g:String="";
var hexColor:String=drawColor.toString(16);
if (hexColor.length == 1)hexColor=
"000000";
else if (hexColor.length == 4) hexColor=
"00"+hexColor;
r=parseInt(hexColor.substr(0,2),16).toString();
g=parseInt(hexColor.substr(2,2),16).toString();
b=parseInt(hexColor.substr(4,2),16).toString();
return r+","+g+","+b;
}
]]>
</mx:Script>
<mx:Panel x=”106” y=”54” width=”250” height=”200” layout=”absolute” title=”Convert To RGB“>
<mx:ColorPicker x=”81” y=”10” id=”colorPicker” change=”rgbValue.text=convertToRGB(event.target.selectedColor);”/>
<mx:Label x=”20” y=”10” text=”color:“/>
<mx:Label x=”20” y=”57” text=”RGB:“/>
<mx:Text x=”72” y=”57” text=”" width=”101” id=”rgbValue“/>
</mx:Panel>
</mx:Application>
I LOVE YOU! Was looking for a “uint to RGB” converter everywhere!
Thanks….Luke
Very helpful indeed. Thanks!
Thanks….Victor
Couldn’t you just do:
Number(colourPicker.selectedColour).toString(16);
Luke.. this will work……but here i am getting the values for RGB
Excellent function, but I get a NaN values when I pick the following blue colors : hex 000033, 000066, 000099, 0000CC, 0000FF.
Hi. all this conversion from uint to string back to int is alot of work. you should look into bitwise functions; for example:
public function convertToRGB(color:uint):String {
& 0xFF;
var r:Number = (color >> 16) & 0xFF;
var g:Number = (color >>
var b:Number = color & 0xFF;
return “” + r + “,” + g + “,” + b;
}
the ‘&’ bitwise comparison only returns bits that are 1 in both numbers. When comparing blue (where n’s are either 0 or 1,s and unwanted):
nnnnnnnnnnnnnnnn10101011 (color:uint)
000000000000000011111111 (0xFF)
returns 10101011
the ( color >> n) shifts color n bits over, so either red or green is in the correct position for comparison (comparing to 0×00FF00 is incorrect)
Thanks!