Styles affect the appearance of components. They alter visual parameters such as border thickness, or replace the entire look of a component with a new image (skin). You can set style properties inline on an MXML tag or separately using CSS code.
When you apply inline styles to components, you can convert component styles into a CSS rule in an external stylesheet. You can also move from the MXML editor to the CSS editor when external styles are used.
Apply inline styles to a component
In Category view, the Styles category lists the styles that can be applied to the selected component.
Apply an external or embedded style to an application
For example, the following expression imports an external style sheet called styles.css:
<mx:Style source="styles.css"/>
The following expression embeds two styles in the MXML file using CSS code:
<mx:Style>
.myclass { color: Red } /* class selector */
Button { fontSize: 10pt; color: Yellow } /* type selector */
</mx:Style>
For styles such as Button, the style is automatically applied to all matching components.
For styles such as .myclass follow these steps:
The Style pop-up menu lists the styles defined in the external style sheet or embedded in the current file.
When external CSS styles are already applied to a component, you can quickly jump from the component to edit these styles.
The CSS file opens in the CSS editor's Design mode. You use the Flex Properties view to make further changes. You can also modify your CSS in Source mode.
The CSS Design mode editor allows you to visually display and edit the contents of a CSS file. As with the MXML editor, you use the Flex Properties view to edit styles. The toolbar gives you quick access to common tasks such as creating and deleting styles, and pan/view. You can also apply skins for Flex components in CSS Design mode.
The type selected determines which components the styles will be applied to. If there is a specific component affected by the new style rule, select a component from the pop-up menu.
When the style is selected, it is previewed in the design area. Use the Flex Properties view to make further changes to your CSS.
For more information, see Using Cascading Style Sheets in the Adobe Flex 3 Developer Guide.
In CSS editor's Design mode you can manipulate CSS and skin styles for Flex components.
When an image file is applied as a skin, the Edit Scale Grid button appears in the upper-right corner of the design area. The scaling grid allows you to visually resize image skins.
The preview switches to editing mode with dotted lines representing the grid.
For more information, see Using 9-slice scaling with embedded images in the Adobe Flex 3 Developer Guide.
When you apply skins to a sub-class of a container (for example, VBox, Panel, Canvas) you may need to adjust the region where the container lays out its child Flex components.
When the selected component has an external style set on it, an Edit button appears next to the Style field. Some components contain entire built-in sub-components with their own style and skin properties. For example, Accordion has section header buttons and List contain a VScrollBar.
While viewing the parent component, click the Edit button.
Flex Builder automatically generates CSS code for both the parent component and the sub-part.
After viewing the sub-part, click the Back button to return to the parent component.
Most style properties that are not explicitly set on the selected item will still have a default value that is inherited through the CSS style chain. For example, ToggleButtonBar inherits any styles applied to ButtonBar.
The Flex Properties view displays default, inherited values for any style properties that are not explicitly set on a selected item. To distinguish default values from values that are not explicitly set, text fields use gray italic text and color swatches use a paler border.
For more information, see Using Styles and Themes in the Adobe Flex 3 Developer Guide.
Many of the features in the CSS Flex Properties view are expanded versions of similar features in the MXML editor. For example, you can also make changes to text, fill, and layout styles from this view.
Additional options in the CSS editor include an expanded fonts list, an Embed This Font option, and color swatches for choosing rollover, selected, and disabled text. The fonts list includes all web fonts, installed OS fonts, TTF files, and any additional embedded fonts in the current CSS file.
For more information, see the Adobe Flex 3 Developer Guide.
You use the Import Skin Artwork wizard to import both vector graphics artwork and bitmap artwork from the CS3 versions of Flash, Fireworks, Illustrator, and Photoshop. (For bitmap artwork, any .PNG, .JPG, or .GIF can be used). The artwork can then be used as skins for Flex components.
In the plugin version, select File > Import > Artwork.
For custom components, the item will be checked if the component has been defined somewhere within the project you are importing to.
A CSS file is created and displayed in the Source view. The CSS file will be attached to the application specified in the wizard. If you import a SWC file, it is automatically added to the library path for the project.
If necessary, you can refresh the MXML and CSS editors' Design mode to render your layout properly. The rendering of your layout can become out of date in certain situations. This can happen, for example, if you modify a visual element in a dependent Flash component (SWC). Styles and skins may also not be rendered properly because Flex Builder needs to rebuild the file.
Click the Refresh button in the editor toolbar.