Setting the border color on a Spark Border container in Flex 4

The following example shows how you can set the border color on a Spark Border container in Flex 4 by setting the borderColor 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 www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

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"?>
<!-- http://blog.flexexamples.com/2009/09/04/setting-the-border-color-on-a-spark-border-container-in-flex-4/ -->
<s:Application name="Spark_Border_borderColor_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">
    <s:controlBarContent>
        <mx:Form paddingTop="0" paddingBottom="0">
            <mx:FormItem label="borderColor:">
                <mx:ColorPicker id="colorPicker" />
            </mx:FormItem>
        </mx:Form>
    </s:controlBarContent>
 
    <s:Border id="brdr"
            borderColor="{colorPicker.selectedColor}"
            horizontalCenter="0" verticalCenter="0">
        <s:RichText width="200">
            <s:textFlow>
                <s:TextFlow>
                    <s:p>1) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>2) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>3) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>4) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>5) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>6) The quick brown fox jumps over the lazy dog.</s:p>
                </s:TextFlow>
            </s:textFlow>
        </s:RichText>
    </s:Border>
 
</s:Application>

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

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/09/04/setting-the-border-color-on-a-spark-border-container-in-flex-4/ -->
<s:Application name="Spark_Border_borderColor_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/halo";
 
        s|Border {
            borderColor: haloBlue;
        }
    </fx:Style>
 
    <s:Border id="brdr"
            horizontalCenter="0" verticalCenter="0">
        <s:RichText width="200">
            <s:textFlow>
                <s:TextFlow>
                    <s:p>1) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>2) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>3) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>4) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>5) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>6) The quick brown fox jumps over the lazy dog.</s:p>
                </s:TextFlow>
            </s:textFlow>
        </s:RichText>
    </s:Border>
 
</s:Application>

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

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/09/04/setting-the-border-color-on-a-spark-border-container-in-flex-4/ -->
<s:Application name="Spark_Border_borderColor_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo">
    <s:controlBarContent>
        <mx:Form paddingTop="0" paddingBottom="0">
            <mx:FormItem label="borderColor:">
                <mx:ColorPicker id="colorPicker"
                        change="colorPicker_change(event);"/>
            </mx:FormItem>
        </mx:Form>
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            import mx.events.ColorPickerEvent;
 
            protected function colorPicker_change(evt:ColorPickerEvent):void {
                brdr.setStyle("borderColor", evt.color);
            }
        ]]>
    </fx:Script>
 
    <s:Border id="brdr"
            horizontalCenter="0" verticalCenter="0">
        <s:RichText width="200">
            <s:textFlow>
                <s:TextFlow>
                    <s:p>1) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>2) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>3) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>4) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>5) The quick brown fox jumps over the lazy dog.</s:p>
                    <s:p>6) The quick brown fox jumps over the lazy dog.</s:p>
                </s:TextFlow>
            </s:textFlow>
        </s:RichText>
    </s:Border>
 
</s:Application>

For more information on the Spark Border container, see the Spark Border specification on the Flex Open Source site.

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.