AS3 RGB Colour to CSS Colour (String)


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



Copy this code and paste it in your HTML
  1. var magentaRed:int = 255;
  2. var magentaGreen:int = 0;
  3. var magentaBlue:int = 255;
  4. var magentaCSS:String = RGBToCSS(magentaRed, magentaGreen, magentaBlue);
  5. trace("magentaCSS: " + magentaCSS);
  6.  
  7. function RGBToCSS(r:int, g:int, b:int):String
  8. {
  9. var hex:uint = r << 16 | g << 8 | b;
  10. return "#" + hex.toString(16).toUpperCase();
  11. }
  12.  
  13. // OUTPUT
  14. // magentaCSS: #FF00FF

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.