Themes
Themes provide a way to compile all .css files, graphical skin asset files, and programmatic skin classes in an .swc file that you can then tell the Flex compiler to use for your Flex application. This has two primary advantages:
It allows you to precompile style and skin assets so that application compilation is faster.
It allows you to more easily distribute and drop in preconfigured styles and skins for Flex applications.
Themes are fantastic when, say, you have a corporate style guide that you need to implement across many applications. Rather than having to distribute all the .css files, graphical elements, and programmatic skin classes, you can distribute just one .swc file.
Setting a Theme
Setting a theme for a Flex application is very simple. All that is necessary is to add a -theme
compiler option to mxmlc
. If you are compiling from the command line (or using Ant
or another automatic build program), you will want to simply add
-theme
themeFile
.swc
to the compiler options, as in this
example:
mxmlc -theme corporate.swc Main.mxml
If you are using Flex Builder to build your application, you
should open the project properties, select the Flex Compiler option, and
add -theme
themeFile
.swc
to the additional compiler arguments
field.
Creating a Theme
To use a theme, you clearly must have a theme first. A theme must contain at least one .css file, and likely contains additional assets such as image assets and/or a programmatic skin class. A theme file must be precompiled as an
Get Programming Flex 3 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.