Setting the unfocused text selection color on a FxTextArea control in Flex Gumbo

In a previous example, “Setting the text selection color on a FxTextArea control in Flex Gumbo”, we saw how you couldset the text selection color on a Flex Gumbo FxTextArea control by setting the selectionColor style.

The following example shows how you can set the unfocused text selection color on a Flex Gumbo FxTextArea control by setting the unfocusedSelectionColor style.

Full code after the jump.

To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3”.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/14/setting-the-unfocused-text-selection-color-on-a-fxtextarea-control-in-flex-gumbo/ -->
<Application name="FxTextArea_unfocusedSelectionColor_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="unfocusedSelectionColor:">
                <ColorPicker id="colorPicker"
                        selectedColor="#FFFF99" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <FxTextArea id="textArea"
            unfocusedSelectionColor="{colorPicker.selectedColor}"
            selectionVisibility="whenActive">
        <content><String source="data/lorem.txt" /></content>
    </FxTextArea>

</Application>

View source is enabled in the following example.

You can also set the unfocusedSelectionColor style in an external .CSS file or <Style> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/14/setting-the-unfocused-text-selection-color-on-a-fxtextarea-control-in-flex-gumbo/ -->
<Application name="FxTextArea_unfocusedSelectionColor_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <Style>
        FxTextArea {
            unfocusedSelectionColor: haloOrange;
        }
    </Style>

    <FxTextArea id="textArea"
            selectionVisibility="whenActive">
        <content><String source="data/lorem.txt" /></content>
    </FxTextArea>

    <FxTextInput text="Click here to remove FxTextArea focus"
            widthInChars="32" />

</Application>

Or, you can set the unfocusedSelectionColor style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/11/14/setting-the-unfocused-text-selection-color-on-a-fxtextarea-control-in-flex-gumbo/ -->
<Application name="FxTextArea_unfocusedSelectionColor_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <Script>
        import mx.events.ColorPickerEvent;

        private function colorPicker_change(evt:ColorPickerEvent):void {
            textArea.setStyle("unfocusedSelectionColor", evt.color);
        }
    </Script>

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="unfocusedSelectionColor:">
                <ColorPicker id="colorPicker"
                        selectedColor="#FFFF99"
                        change="colorPicker_change(event);" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <FxTextArea id="textArea"
            selectionVisibility="whenActive">
        <content><String source="data/lorem.txt" /></content>
    </FxTextArea>

    <FxTextInput text="Click here to remove FxTextArea focus"
            widthInChars="32" />

</Application>

This entry is based on a beta version of the Flex Gumbo 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 Gumbo SDK.

4 thoughts on “Setting the unfocused text selection color on a FxTextArea control in Flex Gumbo

  1. You are doing a great job, Peter, thanks for it :-)
    Request: Can you include a demo for each of the sample you put? It makes it much easier to visualize the effect you talk about.

    Thanks!

  2. I try and do samples when I have time. Unfortunately I’ve been sick/busy lately so not all entries have SWFs.
    The examples are fairly copy/paste-able though, to run this example you just need to put some dummy data in a text file named data/lorem.txt.

    Peter

  3. I understand that it is easy to run them. But I see that you are posting more and more Gumbo examples. I dont have the luxury to keep switching my sdks from time to time, especially when I am working on important projects. I am sure this is true for a lot of flex developers out there. Hence the request.
    I do hope you get better soon :-)

    thanks,
    Om

Comments are closed.