Posted By

adrianparr on 02/09/11


Tagged

css hex red colour color convert RGB as3 Blue Green #


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ezhis


AS3 CSS Colour (String) to RGB Colours (Object)


 / Published in: ActionScript 3
 

  1. var brightPinkCSS:String = "#FF32CC";
  2. var brightPinkRGB:Object = HexToRGB(brightPinkCSS);
  3. trace(brightPinkRGB.r+ ", " + brightPinkRGB.g + ", " + brightPinkRGB.b);
  4.  
  5. function HexToRGB(value:String):Object {
  6. if (value.indexOf("#") != -1) {
  7. value = "0x"+ value.split("#").join("");
  8. } else {
  9. value = "0x"+ value;
  10. }
  11. var hexValue:uint = parseInt(value, 16);
  12. var rgb:Object = new Object();
  13. rgb.r = (hexValue >> 16) & 0xFF
  14. rgb.g = (hexValue >> 8) & 0xFF
  15. rgb.b = hexValue & 0xFF
  16. return rgb;
  17. }
  18.  
  19. // OUTPUT
  20. // 255, 50, 204

Report this snippet  

You need to login to post a comment.