as3 用StyleSheet css 设置文本样式

import flash.text.TextField;
import flash.text.StyleSheet;

var txt:TextField = new TextField();
addChild(txt);
var style:StyleSheet = new StyleSheet();
style.setStyle(".username", {color: "#FF0000",fontWeight:"bold"});

txt.styleSheet = style;
txt.htmlText = "<span class='username'>user</span>aaaaa";

addChild(txt);


var style2:StyleSheet = new StyleSheet();
var heading:Object = new Object();
heading.fontWeight = "bold";
heading.color = "#FF0000";

var body:Object = new Object();
body.fontStyle = "italic";

style2.setStyle(".heading", heading);
style2.setStyle("body", body);

var label:TextField = new TextField();
label.x = 100;
label.styleSheet = style2;
label.htmlText = "<body><span class='heading'>Hello </span>World...</body>";
addChild(label);

posted on 2012-09-15 11:53  防空洞123  阅读(963)  评论(0编辑  收藏  举报

导航