16

I'm working with several components that take color as a uint, but the colors I have are in the format of "#161616". I'm not sure what the relation between the 2 types of colors are or how to go from one to another.

It doesn't have to be an actionscript solution. I have only a small number of these colors, so can be done manually too.

Daryl
  • 247
  • 1
  • 2
  • 7

5 Answers5

38
var color:uint = 0x161616;

Or, to convert them programmatically:

var s:String = "#161616";
var color:uint = uint("0x" + s.substr(1));
Cory Petosky
  • 12,458
  • 3
  • 39
  • 44
3

Be aware that stylesheets in Flex want the color values in the form #FFFFFF ... NOT 0xFFFFFF. MXML element style properties don't care. Although when you start writing something like:

<mx:VBox backgroundColor="

the Intellisense prompts you for a uint value; if you go ahead and complete it like so

<mx:VBox backgroundColor="#FFFFFF"></VBox>

it will still make your backgroundColor the same as if you had written

<mx:VBox backgroundColor="0xFFFFFF"></VBox>
Robusto
  • 31,447
  • 8
  • 56
  • 77
1

the correct way is by using StyleManager.getColorName() see the full documentation

ktutnik
  • 6,882
  • 1
  • 29
  • 34
1

Here you are 2 of my utils functions:

    public static function convertUintToString( color:uint ):String {  
            return color.toString(16);  
    }  

    public static function convertStringToUint(value:String, mask:String):uint {  
            var colorString:String = "0x" + value;  
            var colorUint:uint = mx.core.Singleton.getInstance("mx.styles::IStyleManager2").getColorName( colorString );  

            return colorUint;  
    }     
theaibo
  • 71
  • 1
  • 5
0
var i : uint = uint("0x161616"); 
Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
99miles
  • 10,942
  • 18
  • 78
  • 123