Convert string to uint in actionscript / Flex

I am creating a component and want to set the color property, as many flex controls do, let's say that I have a simple component, for example this, lets call it foo_label:


<mx:Canvas>
    <mx:Script>
        [Bindable] public var color:uint;
    </mx:Script>
    <mx:Label text="foobar" color="{color}" />
</mx:Canvas>

and then add the component to another mxml file, something like lines:


<foo:foo_label color="red" />

When compiling, the compiler complains: it is not possible to parse a value of type uint from the text 'red'. However, if I use a simple shortcut, I can do

<mx:Label text="foobar" color="red">

no problem, and the color property is still a uint type.

, , ? "" uint mx, , , , - ?

.

+3
2

, . :

[Style(name="labelColor", type="uint", format="Color" )]

( , MXML). ActionScript, , , . http://livedocs.adobe.com/flex/3/html/help.html?content=skinstyle_1.html.

+8

- utils:

    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;  
    }     
+2

Source: https://habr.com/ru/post/1697500/


All Articles