15.7. Working with Border and Background Styles

Problem

You want to apply styles to the border and background of a component or components.

Solution

Use the backgroundColor, borderColor, or borderStyle style property.

Discussion

You can set the background and border colors for components using the appropriate styles. For the background, just assign a value to the backgroundColor property. For example, the following code applies a red background to a list named clProducts:

	clProducts.setStyle("backgroundColor", "red");

The background color is one of the styles that does not inherit properly when you apply it globally. That means that it will not take effect for some types of components if you use the following line of code:

	_global.style.setStyle("backgroundColor", "red");

It does inherit correctly for some types of components, such as the combo box, numeric stepper, window, date chooser, and date field. However, it does not properly inherit for other component types, such as list, text input, and text area. One solution is to apply the styles to each component instance, or perhaps each component class. However, that could prove rather unnecessarily tedious. Instead, as a workaround, you can apply the style settings globally as normal. But in addition, define the class style objects for the necessary classes. By just defining the class style object, the global styles will then inherit properly. The following is an example in which you can apply the backgroundColor style globally. If your ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.