这里有 2 个代码块。
var myTextField:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();
addChild(myTextField);
myTextFormat.font = "Arial";
myTextFormat.size = 15;
myTextFormat.color = 0x0000FF;
myTextField.text = "some text";
**myTextField.setTextFormat(myTextFormat);**
VS
var myTextField:TextField = new TextField();
var myTextFormat:TextFormat = new TextFormat();
addChild(myTextField);
myTextFormat.font = "Arial";
myTextFormat.size = 15;
myTextFormat.color = 0x0000FF;
**myTextField.defaultTextFormat = myTextFormat;**
那么, setTextFormat() 和 defaultTextFormat 有什么区别呢?为什么用两种不同的方式(一种按属性,另一种按方法)做事。
用更多代码测试:
var my_txt:TextField =new TextField();
my_txt.type = TextFieldType.INPUT
var my_fmt:TextFormat = new TextFormat();
my_fmt.color = 0xFF0000;
my_txt.text = "this is for setTextFormat with range";
my_txt.setTextFormat(my_fmt,0,3);
// my_txt.text = "this is for setTextFormat without range";
// my_txt.setTextFormat(my_fmt);
// my_txt.defaultTextFormat = my_fmt;
// my_txt.text = "this is for default text format";
addChild(my_txt);
五。