2013-03-01 19 views
0

我有這段代碼。它會在舞臺上創建兩行文字,但是當舞臺重新調整大小時,第二行文字會在舞臺縮放時消失。有誰知道爲什麼會發生這種情況?提前謝謝你的幫助!爲什麼當舞臺重新調整大小的ActionScript 3時,第二行文本會消失?

var text:TextField=new TextField(); 
var textFormat:TextFormat = new TextFormat(); 
textFormat.color=0x000000; 
textFormat.size=45; 
textFormat.bold=true; 
textFormat.font="Impact"; 
textFormat.italic=true; 
text.x=8; 
text.y=5; 
text.width=200; 
text.text = "Line One\nLine two"; 
text.setTextFormat(textFormat); 
text.height=text.textHeight +4; 
sprite.addChild(text); 

然後將精靈添加到舞臺上。

回答

0

試試下面的代碼:

var text:TextField=new TextField(); 
var textFormat:TextFormat = new TextFormat(); 
textFormat.color=0x000000; 
textFormat.size=45; 
textFormat.bold=true; 
textFormat.font="Impact"; 
textFormat.italic=true; 
text.x = 8; 
text.border = true; 
text.y=5; 
text.width=200; 
text.text = "Line One\nLine two"; 
text.setTextFormat(textFormat); 
text.autoSize = TextFieldAutoSize.LEFT; 
sprite.addChild(text); 

注意添加了自動調整大小,這似乎解決您的問題。

+0

所以它的工作,但切割的結束,除非我刪除斜體奇數感謝您的幫助!我不知道這一點。 – Justin 2013-03-01 23:27:11

+0

看看這個問題和答案:http://stackoverflow.com/questions/1516391/textfield-autosizeitalics-cuts-of-last-character 在行後添加一個空格有助於還有其他解決方案,但主要是黑客工作。 – 2013-03-01 23:37:41

相關問題