使用外部 CSS 来设置 Flash MX 2004 组件外观

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"); 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值