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


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.