Return to Snippet

Revision: 40912
at February 9, 2011 22:07 by adrianparr


Initial Code
var brightPinkCSS:String = "#FF32CC";
var brightPinkRGB:Object = HexToRGB(brightPinkCSS);
trace(brightPinkRGB.r+ ", " + brightPinkRGB.g + ", " + brightPinkRGB.b);

function HexToRGB(value:String):Object {	
	if (value.indexOf("#") != -1) {
		value = "0x"+ value.split("#").join("");
	} else {
		value = "0x"+ value;
	}
	var hexValue:uint = parseInt(value, 16);
	var rgb:Object = new Object();
	rgb.r = (hexValue >> 16) & 0xFF
	rgb.g = (hexValue >> 8) & 0xFF
	rgb.b = hexValue & 0xFF			
	return rgb;
}

// OUTPUT
// 255, 50, 204

Initial URL

                                

Initial Description

                                

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

Initial Tags
css, color, convert

Initial Language
ActionScript 3