Setting the disabled alpha on a Spark TextInput control in Flex 4

In a previous example, “Styling the disabled state on a Spark TextInput control in Flex 4”, we saw how you could style the disabled state on a Spark TextInput control in Flex 4 using CSS.

The following example shows how you can set the alpha of the disabled state of a Spark TextInput control in Flex 4 by creating a custom Spark TextInput skin and setting the alpha property on the disabled skin state.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see To download the latest nightly build of the Flex 4 SDK, see

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:Application name="Spark_TextInput_skin_alpha_test"
        <s:VerticalLayout horizontalAlign="center" verticalAlign="middle" />
        <s:CheckBox id="chckBx" label="enabled" selected="true" />
    <s:TextInput id="txtInp1"
            text="Default Spark TextInput"
            width="300" />
    <s:TextInput id="txtInp2"
            text="Spark TextInput w/ custom skin"
            width="300" />

And the custom Spark TextInput skin, skins/CustomTextInputSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:SparkSkin name="CustomTextInputSkin"
    <!-- states -->
        <s:State name="normal"/>
        <s:State name="disabled"/>
    <fx:Script fb:purpose="styling">
            private var paddingChanged:Boolean;
            /* Define the skin elements that should not be colorized. */
            static private const exclusions:Array = ["background", "textDisplay"];
            override public function get colorizeExclusions():Array {
                return exclusions;
            /* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
            static private const contentFill:Array = ["bgFill"];
            override public function get contentItems():Array {
                return contentFill;
            override protected function commitProperties():void
                if (paddingChanged)
                    paddingChanged = false;
            override protected function initializationComplete():void
                useChromeColor = true;
            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                if (getStyle("borderVisible") == true)
                    border.visible = true;
                    shadow.visible = true;
                    background.left = = background.right = background.bottom = 1;
                    textDisplay.left = = textDisplay.right = textDisplay.bottom = 1;
                    border.visible = false;
                    shadow.visible = false;
                    background.left = = background.right = background.bottom = 0;
                    textDisplay.left = = textDisplay.right = textDisplay.bottom = 0;
                borderStroke.color = getStyle("borderColor");
                borderStroke.alpha = getStyle("borderAlpha");
                super.updateDisplayList(unscaledWidth, unscaledHeight);
            private function updatePadding():void
                if (!textDisplay)
                // Push padding styles into the textDisplay
                var padding:Number;
                padding = getStyle("paddingLeft");
                if (textDisplay.getStyle("paddingLeft") != padding)
                    textDisplay.setStyle("paddingLeft", padding);
                padding = getStyle("paddingTop");
                if (textDisplay.getStyle("paddingTop") != padding)
                    textDisplay.setStyle("paddingTop", padding);
                padding = getStyle("paddingRight");
                if (textDisplay.getStyle("paddingRight") != padding)
                    textDisplay.setStyle("paddingRight", padding);
                padding = getStyle("paddingBottom");
                if (textDisplay.getStyle("paddingBottom") != padding)
                    textDisplay.setStyle("paddingBottom", padding);
            override public function styleChanged(styleProp:String):void
                var allStyles:Boolean = !styleProp || styleProp == "styleName";
                if (allStyles || styleProp.indexOf("padding") == 0)
                    paddingChanged = true;
            private static const focusExclusions:Array = ["textDisplay"];
            override public function get focusSkinExclusions():Array {
                return focusExclusions;
    <!-- border -->
    <s:Rect left="0" right="0" top="0" bottom="0" id="border">
            <s:SolidColorStroke id="borderStroke" weight="1" />
    <!-- fill -->
    <!--- Defines the appearance of the TextInput component's background. -->
    <s:Rect id="background" left="1" right="1" top="1" bottom="1">
            <!--- Defines the background fill color. -->
            <s:SolidColor id="bgFill" color="0xFFFFFF" />
    <!-- shadow -->
    <s:Rect left="1" top="1" right="1" height="1" id="shadow">
            <s:SolidColor color="0x000000" alpha="0.12" />
    <!-- text -->
    <s:RichEditableText id="textDisplay"
            left="1" right="1" top="1" bottom="1" />

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.