views:

458

answers:

1

Good day everyone,

I am stuck trying to convert a uint color value into its equivalent argb hexadecimal format. Basically, I am trying to convert a color from Flex(AS3) into its appropriate kml color, which is in the argb hexadecimal format from what I gather. Below is my function as it stands now. Although it does convert into a valid kml color, it is not the right color or even close. Does anyone see anything wrong here?

    private static function getKmlColor(color:uint,alpha:Number):String
    {
        var argb:uint = 0;
        var alphaUint:uint = 255 * alpha;
        argb += (alphaUint<<24);
        argb += (color);
        return argb.toString(16);
    }  
+1  A: 

I assume your alpha is something between 0 and 1 (0-100%) so that should be fine, although I'd probably make it a double and then floor or ceiling to the nearest whole number.

But the rest seems OK

PSU_Kardi
You are correct about the alpha, it is a value between 0 and 1. Good point about the rounding (or lack thereof).