views:

472

answers:

3

I have a TextField that is formatted with bold and blue. Then, when I change the 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";

+1  A: 

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" ;
St.Woland
If I recall correctly, setNewTextFormat is a AS2 language method only.
Tyler Egeto
+10  A: 

Hi there,

In AS3 you will want to use the defaultTextFormat property of TextField object's.

Tyler Egeto
A: 

Tyler's correct. More specifically:

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

Hope this helps!

marcelebrate