The following example shows how you can set the background fill color on the Halo TextArea control (with default Spark skin) in Flex 4 by setting the contentBackgroundColor style (in Flex 3 and earlier this was done by setting the backgroundColor 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 beta, check out the Adobe Flash Builder 4 page on the Adobe Labs site. To download the latest build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. For instructions on using the beta Flex 4 SDK in Flex Builder 3, see "Using the beta Flex 4 SDK in Flex Builder 3".
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/06/17/setting-the-background-fill-color-on-a-halo-textarea-control-in-flex-4/ --> <s:Application name="TextArea_SparkSkin_contentBackgroundColor_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"> <mx:ApplicationControlBar width="100%" cornerRadius="0"> <mx:Form styleName="plain"> <mx:FormItem label="contentBackgroundColor:"> <mx:ColorPicker id="colorPicker" selectedColor="white" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:TextArea id="textArea" text="The quick brown fox jumps over the lazy Doug." contentBackgroundColor="{colorPicker.selectedColor}" horizontalCenter="0" verticalCenter="0" /> </s:Application>
You can also set the contentBackgroundColor style in an external .CSS file or <Script> block, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/06/17/setting-the-background-fill-color-on-a-halo-textarea-control-in-flex-4/ --> <s:Application name="TextArea_SparkSkin_contentBackgroundColor_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 mx "library://ns.adobe.com/flex/halo"; @namespace s "library://ns.adobe.com/flex/spark"; mx|TextArea { contentBackgroundColor: haloSilver; } </fx:Style> <mx:TextArea id="textArea" text="The quick brown fox jumps over the lazy Doug." horizontalCenter="0" verticalCenter="0" /> </s:Application>
Or, you can set the contentBackgroundColor style using ActionScript, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/06/17/setting-the-background-fill-color-on-a-halo-textarea-control-in-flex-4/ --> <s:Application name="TextArea_SparkSkin_contentBackgroundColor_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:Script> <![CDATA[ import mx.events.ColorPickerEvent; private function colorPicker_change(evt:ColorPickerEvent):void { textArea.setStyle("contentBackgroundColor", evt.color); } ]]> </fx:Script> <mx:ApplicationControlBar width="100%" cornerRadius="0"> <mx:Form styleName="plain"> <mx:FormItem label="contentBackgroundColor:"> <mx:ColorPicker id="colorPicker" selectedColor="white" change="colorPicker_change(event);" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:TextArea id="textArea" text="The quick brown fox jumps over the lazy Doug." horizontalCenter="0" verticalCenter="0" /> </s:Application>
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.

{ 5 comments… read them below or add one }
Hi Peter..
How to apply gradient background colors dynamically to the Halo TextArea?
@AV,
You can set a gradient Halo/MX TextArea background in Flex 4 by creating a custom border skin and setting a LinearGradient background fill, as seen in the following example:
And the custom border skin, skins/TextAreaBorderSkin.mxml, is as follows:
Peter
Re-posted at “Setting a gradient background fill on a Halo TextArea control in Flex 4″.
Peter
And this is easy to do dynamically with the Spark TextArea (still trying to figure out how/if you can do this easily at runtime using ActionScript with the Halo/MX TextArea):
Peter
Re-posted (and expanded) at “Setting a gradient background fill on a Spark TextArea control in Flex 4″.
Peter