So lets take a look at runtime CSS in Flex 2.0.1. This is a killer feature for me because in allows for reusable skinning across Flex applications as simple as a URL. Now your expecting CSS to be text based but in Flex’s case to support custom fonts, custom component skins, and graphics embedding the runtime format of CSS in Flex is SWF.
Runtime CSS Example
In Flex 2.0.1 there is a new compiler option for MXMLC to directly compile CSS into SWF. These style SWF files can then be loaded at runtime by any Flex 2.0.1 application. This is very handy because it allows you to externalize all graphical elements within the style of your application into a URL for reuse across applications. Why embed the style N times when you can externalize it and just load it in? Typically you are not just making 1 Flex application, you may be making 5-6 for the intranet at your company and externalizing style in this format is very handy.
First you need to create a CSS file. I typically go to the Flex 2 Style Explorer to style my applications. It presents all the style options for Flex components and generates CSS for you. It is one of my secret weapons.
Flex 2 Style Explorer
Download Flex Style Explorer ZIP
So now for the hard part, compilation. Assume I have a style sheet called ‘style1CSS.css’ and all assets required are located adjacent to the ‘style1CSS.css’ file. With mxmlc in your path, simply write this on the command line.
mxmlc style1CSS.css
This creates the SWF file ‘style1CSS.swf’.
If you are using Flex Builder 2.0.1 just right-click on the CSS file and press “Compile CSS to SWF”. The swf file will be put into the ‘bin’ directory.
Now from within your application, you need to load this SWF via the Style Manager like so. Here is the application source for the example below:
<mx:Application
xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”absolute”
initialize=”StyleManager.loadStyleDeclarations( ’style1CSS.swf’ )”
viewSourceURL=”srcview/index.html”>
<mx:ComboBox
id=”styleCombo”
top=”10″ left=”10″ right=”10″
dataProvider=”['style1CSS','style2CSS','style3CSS']“
change=”StyleManager.loadStyleDeclarations( styleCombo.selectedItem + ’.swf’ )”>
</mx:Application>
In this case, the StyleManager loads the style1CSS.swf on the initialize event. I also provided a comboBox that will load CSS Style SWF files when the change event occurs.
Runtime CSS Example
So that is runtime CSS in a nutshell. What I think would be great is for everyone to create styles CSS SWF files and share them publicly. It would allow anyone to create a styled application without any style data in the core application. Simply map the components to the style classes in the CSS SWF, and they will all update when the CSS Style SWF file loads.
원문:http://www.onflex.org/ted/2007/01/flex-201-understand-runtime-css.php