Reputation: 2063
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";
Upvotes: 2
Views: 4628
Reputation: 1690
Tyler's correct. More specifically:
myTextField.defaultTextFormat = myTextField.getTextFormat();
myTextField.text = "Sample text.";
Hope this helps!
Upvotes: 4
Reputation: 5495
In AS3 you will want to use the defaultTextFormat
property of TextField
object's.
Upvotes: 13
Reputation: 5427
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" ;
Upvotes: 2