Applying stylesStyles affect the appearance of an application by specifying values for visual parameters for application components. You can set styles that apply to all components in an application, to individual components, or to a set of components referenced by a style selector. For example, you can specify styles such as:
Note: The styles available for a component varies, according to
the component.
You set style properties inline on an MXML tag or separately using CSS code. The CSS code can be inside <fx:Style> tags in an application or in a separate CSS file. When you apply inline styles to components, you can convert component styles into a CSS rule in an external stylesheet. You can use the CSS editor to edit CSS files. You can also convert skins applied to a component into styles. Use Design mode of the MXML editor to apply styles to an application or specific application components. You can also use Design mode to convert applied styles or skins to CSS stylesheets. Styles compared to skinsSkinning is the process of changing the appearance of a component by modifying or replacing its visual elements. These elements can be made up of bitmap images, SWF files, or class files that contain drawing methods that define vector images.Skins can define the appearance of a component in various states. For example, you can specify the appearance of a Button component in the up, down, over, and disabled states. Using Flash Builder, you can convert a component’s skin to CSS styles. Apply styles to an applicationUse the Appearance view to define styles that apply to an entire application. Flash Builder saves the style defined in Appearance view as a global CSS style selector.
Apply inline styles to a componentUse the Properties view to define inline styles for selected components.
Apply an external or embedded style to an applicationYou can embed CSS styles in an MXML application file or reference an external CSS file. The following example shows CSS code to apply styles to all Spark Button components in an application. It also creates a selector, .myStyle, that can be applied to any component: @namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
s|Button { fontSize: 16pt; color: Red } /* type selector */
.myStyle { color: Red } /* class selector */
For styles applied to components, such as s|Button, the selector for components must specify a namespace. In this example, s|Button defines a style that is automatically applied to all Spark Button components. Use the CSS period notation to create a selector that can be applied to any component. In this example, .myStyle does not have to declare a namespace and can be applied to any component. Flex has specific requirements for creating and applying styles. For details, see Using styles in Flex. Apply styles to an application
Convert to CSSYou can convert inline styles and component skins to CSS styles. During the conversion, you can specify whether to make the styles global or to apply to a specific component. You can also specify a CSS style selector for the generated styles.
Edit style ruleWhen external CSS styles are already applied to a component, you can quickly jump from the component to edit these styles.
Creating CSS filesUse the New CSS File wizard to create CSS files for a project. The New CSS File wizard creates a blank file that you can use to define your CSS styles. By default, Flash Builder adds the default namespaces for Spark and MX styles. To create a blank CSS file:
Flash Builder uses templates that define the contents of newly created files. You can customize the templates that Flash Builder uses. See Customizing File Templates. Using the CSS editorFlash Builder provides a CSS editor which you can use to create and edit style sheets for your application. The CSS editor is available only in Source mode. When you create a new style sheet in Flash Builder, Flash Builder provides the following declarations for the Spark and MX namespaces: @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/mx"; Some Spark and MX components share the same local name. For example, there is a Spark Button component (in the spark.components.* package) and a MX Button component (in the mx.controls.* package). To distinguish between different components that share the same name, you specify namespaces in your CSS that apply to types. If you do not use type selectors in your style sheets, then you are not required to declare namespaces. For more information, including examples, see About namespaces in CSS. Note: Styles are handled differently for applications that use
the Flex 3 SDK. If you are working in a Flex project that specifies
the Flex 3 SDK, the CSS editor reverts to behavior implemented with
Flex Builder 3. Refer to the Flex Builder 3 documentation for information
on using the CSS editor for applications that use the Flex 3 SDK.
|
|