2

I have a TextField that is formatted with bold and blue. However, when I change TextField.text, the formatting of the textfield resets and I have to setTextFormat again.

This is the code I use to set my TextField. myText is the variable for my TextField. (This is just part of my code; it is part of a function for my EventListener.)

yourName = body_txt.text;  
myText.text = "This is the new text";
4

3 回答 3

13

在 AS3 中,您将需要使用对象的defaultTextFormat属性TextField

于 2010-01-19T07:49:12.620 回答
4

泰勒是对的。进一步来说:

myTextField.defaultTextFormat = myTextField.getTextFormat();
myTextField.text = "Sample text.";

希望这可以帮助!

于 2010-06-16T20:24:31.457 回答
2

You should use setNewTextFormat instead, this will affect future changes.

Or, optionally (if you already have some text), apply new format to both properties:

var myTextField:TextField = new TextField();
myTextField.text = "Chunky bacon" ;

var newFormat:TextFormat = new TextFormat();
newFormat.color = 0xFF0000;
newFormat.size = 18;
newFormat.underline = true;
newFormat.italic = true;

myTextField.setTextFormat( newFormat ) ; // Applies to current value – "Chunky bacon"
myTextField.setNewTextFormat( newFormat ) ; // Applies to future changes - " Hello World"

myTextField.text += " Hello World" ;
于 2010-01-19T07:35:31.097 回答