ここに 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 の違いは何ですか? 物事を行うための 2 つの異なる方法 (1 つはプロパティ別、もう 1 つはメソッド別) です。
いくつかのコードでテスト済み:
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);
V.