我正在尝试更新一些TextField的样式,例如。 color,fontSize,fontFamily。 我正在创建字段:
var textField:TextField = new TextField();
var style:StyleSheet = new StyleSheet();
style.parseCSS("p{color: #000000; fontFamily: System; fontSize: 20px;}");
textField.styleSheet = style;
textField.selectable = false;
//textField.embedFonts = true;
textField.antiAliasType = AntiAliasType.ADVANCED;
///textField.defaultTextFormat = myFormat;
textField.text = text;
textField.wordWrap = true;
textField.width = 800;
textField.height = 40;
some_other_mc.addChild(textField);
然后我正在尝试更新 textField:
private function SetStyle(name:String, value:String):void {
var current_styles:Object = _active_text_field.styleSheet.getStyle('p');
switch(name) {
case 'color':
current_styles.color = value;
break;
case 'fontSize':
current_styles.fontSize = value;
break;
case 'fontFamily':
current_styles.fontFamily = value;
break;
}
_active_text_field.styleSheet.setStyle('p', current_styles);
}
_active_text_field 链接到 textField 。
每个触发器SetStyle都不做任何更改。我很长时间都找不到bug。
请感谢您的帮助:)
答案 0 :(得分:0)
我建议你采取这个简单的样本
package {
import flash.display.Sprite;
import flash.text.StyleSheet;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
public class StyleSheetExample extends Sprite {
public function StyleSheetExample() {
var style:StyleSheet = new StyleSheet();
var heading:Object = new Object();
heading.fontWeight = "bold";
heading.color = "#FF0000";
var body:Object = new Object();
body.fontStyle = "italic";
style.setStyle(".heading", heading);
style.setStyle("body", body);
var label:TextField = new TextField();
label.styleSheet = style;
label.htmlText = "<body><span class='heading'>Hello </span>World...</body>";
addChild(label);
}
}
}