A simple utility class that will help you convert a color value (from numbers) to hexadecimal color value.
Basically you can convert the color value to hex string with colorNumber.toString(16);
Now, if you have this shade of blue “13311”, for example, it will be converted to “33ff”.
You can fix that with while(hexColor.length < 6) and add “0” to in front of the hex color output.
The final code will look something like this:
var hexColor:String = number.toString(16); while(hexColor.length < 6) hexColor = "0" + hexColor; |
The entire class is below. You can copy it and use it as you wish.
package com.vamapaull.utils { public class ColorToHexadecimal { public static function convertToHexString(number:Number):String { var hexColor:String = number.toString(16); while(hexColor.length < 6) hexColor = "0" + hexColor; return hexColor; } } } |