Setting the focus alpha on a Spark TextArea control in Flex 4

The following example shows how you can set the focus alpha on the Spark TextArea control in Flex 4 by setting the focusAlpha style.

Full code after the jump.

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_TextArea_focusAlpha_test"
        <mx:Form contentBackgroundAlpha="0">
            <mx:FormItem label="focusAlpha:">
                <s:HSlider id="slider"
                        change="txtArea.setFocus();" />
            <mx:FormItem label="focusColor:">
                <mx:ColorPicker id="colorPicker"
                        change="callLater(txtArea.setFocus);" />
    <s:TextArea id="txtArea"
            horizontalCenter="0" verticalCenter="0"

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.

2 thoughts on “Setting the focus alpha on a Spark TextArea control in Flex 4

    1. @Tim S,

      It’s a timing thing. Initially I tried just calling txtArea.setFocus() from the ColorPicker control’s change handler, like so:

      <mx:ColorPicker id="colorPicker"
              change="txtArea.setFocus();" />

      But whenever I ran the code, the focus went back to the ColorPicker control. The ColorPicker control is a bit of a odd component. When you open the ColorPicker, the TextInput control in the pop up receives focus. When you close the ColorPicker control, the ColorPicker itself gets the focus. So long story longer, I had to use the callLater() function to delay the call to txtArea.setFocus() slightly so that the focus would correctly get set on the TextArea control.

      I agree, perhaps not the best solution (you will see a slight flicker as the focus goes from the ColorPicker back to the TextArea), but then again, I don’t suspect many people would be changing the focusAlpha and focusColor styles at runtime like this.


Comments are closed.