Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Flex Developer Center / Flex Quick Starts /

Styling components

by Adobe

Adobe logo

Created

22 March 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flex
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

User level

All

Required products

  • Flex (Download trial)

Styles are useful for defining the look and feel (appearance) of your Adobe Flex applications. You can use them to change the appearance of a single component, or apply them across all components.

There are many ways to apply styles in Flex. Some provide more granular control and can be performed programmatically. Others are not as flexible, but can require less computation. In Flex, you can apply styles to controls in the following ways:

  • Using local style definitions
  • Using external style sheets
  • Using the setStyle() method

Flex does not support controlling all visual aspects of a component with Cascading Style Sheets (CSS). Properties such as x, y, width and height are properties, not styles, of the UIComponent class and, therefore, cannot be set in CSS. You must also be aware of which properties your theme supports. The default theme in Flex does not support all style properties.

A theme is a set of styles that define the look and feel of a Flex application. A theme can define something as simple as the color scheme or common font for an application, or it can be a complete reskinning of all the components used by the application. Themes usually take the form of a SWC file. However, themes can also be a CSS file and embedded graphical resources, such as symbols from a SWF file.

Note: For more information on supported style properties in themes see "About themes" in the Flex 4 documentation. To determine the styles that a specific visual component supports, see the styles section of the component in ActionScript 3 Reference for the Adobe Flash Platform.

Using local style definitions

You can create local style definitions in your MXML files using the <fx:Style> tag. This tag contains style sheet definitions that adhere to the CSS 2.0 syntax. These definitions apply to the current document and all children of the current document.

The following example creates two class selectors, .fontStyle and .backgroundColor. The BorderContainer , Button, and one of the Labels apply the styles using their styleName properties. As this example shows, using class selectors lets you give different styles to instances of the same component.

Example

<?xml version="1.0" encoding="utf-8"?> <!-- StylesStyleTag --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="150" height="140"> <s:layout> <s:VerticalLayout paddingTop="10"/> </s:layout> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/mx"; .fontStyle { font-family : Arial, Helvetica, sans-serif; font-weight : bold; color: maroon; } .backgroundColor { background-color: #ffffcc; } </fx:Style> <s:BorderContainer styleName="backgroundColor" width="100%" height="100%"> <s:layout> <s:VerticalLayout gap="10" horizontalAlign="center" paddingTop="10"/> </s:layout> <s:Label text="Unstyled Text"/> <s:Label text="Styled Text" styleName="fontStyle"/> <s:Button styleName="fontStyle" label="Submit"/> </s:BorderContainer> </s:Application>

Tip: If you want all instances of a certain component to share the same style, you can use a CSS type selector. For example, by using the following type selector, all BorderContainer instances in your application will have a background color of blue.

BorderContainer{ backgroundColor: #ccffff; }

Result

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Back to top

Using external style sheets

Flex supports external CSS style sheets. To apply a style sheet to the current document and its child documents, use the source property of the <fx:Style> tag. External style sheet files should be in the folder that contains your MXML source files. By default, this is the src folder in your MXML project.

Note: You should try to limit the number of style sheets used in an application, and set the style sheet only at the top-level document in the application (the document that contains the <s:Application> tag). If you set a style sheet in a child document, unexpected results can occur.

The following example defines two CSS class selectors in an external CSS file called external.css. You use an external CSS file in a Flex application by specifying its path and file name in the source property of the <fx:Style> tag.

Example:

External CSS file

/* CSS file */ @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/mx"; .fontStyle { font-family : Arial, Helvetica, sans-serif; font-weight : bold; color: blue; } .backgroundColor { background-color: #ccffff; }

MXML file

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="150" height="140"> <!-- StylesExternal.mxml --> <s:layout> <s:VerticalLayout paddingTop="10"/> </s:layout> <fx:Style source="styles/external.css"/> <s:BorderContainer styleName="backgroundColor" width="100%" height="100%"> <s:layout> <s:VerticalLayout gap="10" horizontalAlign="center" paddingTop="10"/> </s:layout> <s:Label text="Unstyled Text"/> <s:Label text="Styled Text" styleName="fontStyle"/> <s:Button styleName="fontStyle" label="Submit"/> </s:BorderContainer> </s:Application>

Result

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Back to top

Using the setStyle() method

Use the setStyle() method to manipulate style properties on instances of controls in ActionScript. This method of applying styles requires a greater amount of processing power on the client than style sheets. However setStyle() provides more granular control over how styles are applied.

The setStyle() method takes two arguments: the style name and the style value.

Tip: When you are instantiating an object and setting the styles for the first time, you should try to apply style sheets rather than use the setStyle() method, which is computationally expensive. You should use this method only when you are changing an object's styles during run time.

Example

<?xml version="1.0" encoding="utf-8"?> <!-- StylesSetStyle.mxml --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="160" height="160" creationComplete="application_creationCompleteHandler(event)"> <s:layout> <s:VerticalLayout paddingTop="10"/> </s:layout> <fx:Script> <![CDATA[ public function application_creationCompleteHandler(e:Event):void { styleManager.getStyleDeclaration("global").setStyle("fontSize", 14); styleManager.getStyleDeclaration("global").setStyle("color", "blue"); styleManager.getStyleDeclaration("spark.components.BorderContainer").setStyle("backgroundColor", "#ffddff"); } ]]> </fx:Script> <s:BorderContainer width="100%" height="100%"> <s:layout> <s:VerticalLayout gap="10" horizontalAlign="center" paddingTop="10"/> </s:layout> <s:Label id="myLabel" text="Styled Text"/> <s:Button id="myButton" label="Submit"/> </s:BorderContainer> </s:Application>

Result

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Back to top

For more information

  • Styles and Themes

Back to top


This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement