While working on a project at Schematic, I was investigating the possibility of defining style attributes for component instances in an external CSS file. I got the following system to work:
1. Create an external CSS file, defining the style(s) and component-specific styles you want to customize. For example:
/* Filename: styles.css */
checkbox {
color: 0x0000FF;
embedFonts: false;
fontFamily: Arial;
fontSize: 24;
}
2. Load the style sheet into your Flash movie, retrieve the style name, and apply it to your instance:
import mx.controls.CheckBox;
var oStyle:Object;
var ccbTest:mx.controls.CheckBox;
var styles = new TextField.StyleSheet();
styles.onLoad = function(bSuccess:Boolean):Void {
if (bSucess) {
oStyle = this.getStyle("checkbox");
for(var i in oStyle){
ccbTest.setStyle(i, oStyle[i]);
}
} else {
trace("Error loading CSS file.");
}
};
styles.load("styles.css");
--From (http://blogs.flashsupport.com/robert/archive/2004/09/08/209.aspx)
--翻译版
编者注:我们都知道可以轻松的设置 Flash MX 2004 组件的外观,但是如果能用一个外部的 CSS 文件来控制,岂不是更好,使用起来就会更加的方便。这里是在网上发现的一个例子(原文网址: http://blogs.flashsupport.com/robert/archive/2004/09/08/209.aspx ):
1. 创建一个 CSS 文件,定义组件的一些属性,如: /* Filename: styles.css */
checkbox { color: 0x0000FF; embedFonts: false; fontFamily: Arial; fontSize: 24; } |
2. 在 Flash 中载入这个 CSS 文件,将组件套上相关的样式:
import mx.controls.CheckBox; var oStyle:Object; var ccbTest:mx.controls.CheckBox; var styles = new TextField.StyleSheet(); styles.onLoad = function(bSuccess:Boolean):Void { if (bSucess) { oStyle = this.getStyle("checkbox"); for(var i in oStyle){ ccbTest.setStyle(i, oStyle[i]); } } else { trace("Error loading CSS file."); } }; styles.load("styles.css"); |