2010-01-19 74 views
2

我有一個用粗體和藍色格式化的TextField。但是,當我更改TextField.text時,textfield的格式重置,我必須再次setTextFormatActionscript TextFormat在更改TextField.text時重置

這是我用來設置我的TextField的代碼。 myText是我的TextField的變量。 (這只是我的代碼的一部分,但是它是我的EventListener功能的一部分)

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

回答

13

在AS3你將要使用的TextField對象在defaultTextFormat屬性。

2

您應該使用setNewTextFormat代替,這將影響未來的變化。

,或者任選地(如果你已經有一些文本),應用新的格式,以這兩個屬性:

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" ; 
+3

如果我沒有記錯,setNewTextFormat只是一種AS2語言方法。 – 2010-01-19 07:47:06

4

泰勒的正確。更具體地說:

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

希望這有助於!

相關問題