2013-03-06 36 views
1

可以設置在TLFTextField上顯示的最大線數?所以我有一個文本比我不想在整個文本上顯示,只有3個第一行可見。我該如何配置?Flash - 在TLFTextField上設置最大線數

這是我還沒有:

  var myTLFTextField:TLFTextField = new TLFTextField(); 
     addChild(myTLFTextField); 
     myTLFTextField.x = 0; 
     myTLFTextField.y = 0; 
     myTLFTextField.width = _width 
     myTLFTextField.height = 100; 
     myTLFTextField.multiline = true; 
     myTLFTextField.wordWrap = true; 


     var myFormat:TextLayoutFormat = new TextLayoutFormat(); 
     myFormat.color = 0x336633; 
     myFormat.fontFamily = "Arial, Helvetica, _sans"; 
     myFormat.fontSize = 24; 
     myFormat.textAlign = TextAlign.LEFT; 

     var textFlow:TextFlow = myTLFTextField.textFlow; 
     var p:ParagraphElement = new ParagraphElement(); 
     var span1:SpanElement = new SpanElement(); 
     var span2:SpanElement = new SpanElement(); 
     var inlineGraphicElement:InlineGraphicElement = new InlineGraphicElement(); 
     var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat(); 

     //Add graph 
     inlineGraphicElement.source = drwCircle(); 
     inlineGraphicElement.float = Float.LEFT; 

     //Add Text to the spans 
     span1.text = "You can draw a happy face here "; 
     span2.text = "if you like.as asdfads ad fas fadsf f asdfsdf asd sdafas dff asd adsf adsf adsf asf sadf asdf dfghjf j fhj fgffg hgfhj fg fgj fg jkb asdljk ljka jlkj asdjfh lajsdfh sd sdf asdfasd fdas asd fa sdfadsf asd adsf ad fadsf adsf ads fads fads f adsf asdf "; 
     p.fontSize = 16; 
     p.addChild(inlineGraphicElement); 
     p.addChild(span1); 
     p.addChild(span2); 


     // Add Paragraph to text flow and update controller to display 
     textFlow.addChild(p); 
     textFlow.hostFormat = myFormat; 
     textFlow.flowComposer.updateAllControllers(); 

回答

0

你可以用另一剪輯隱藏四溢文本掩蔽的區域。

1

幸運的是,使用TLFTextfield我們有像文本的paddingToppaddingBottom和總像素爲textHeight的屬性。也知道文本字段中的文本總數爲numLines,我們可以計算出有多少像素高度我們想要顯示的行數將會佔用多少。

編輯:我注意到,在文本框的一些相當smalllish寬度的numLines屬性不抱預期值...我不知道這可能是一個錯誤,但在此之前看完計算似乎可以解決它。

試試這個(將這些行後,所有的代碼):

//Pre read numLines property :(
myTLFTextField.numLines; 

//how many lines you want to show 
var numLines:uint = 3; 

//set textfield height to the proportion between the total lines of text and 
//the number of lines to show, taking into account the paddings of text 
myTLFTextField.height = myTLFTextField.paddingTop + 
         myTLFTextField.paddingBottom + 
         (myTLFTextField.textHeight*(numLines+1)/myTLFTextField.numLines); 

希望這有助於!

+0

感謝您的回答,如果我不需要在我的「文本字段」上使用任何圖像,但是我需要在文本的左側顯示圖像並且文本必須小於圖像,所以你的解決方案也會削減我的形象。但是我想我發現了一個使用TruncationOptions的解決方案(我剛剛在幾個小時前發現它),當我解決了我將發佈我的解決方案。謝謝無論如何,這將有助於其他情況:) – 2013-03-07 10:33:57

+0

很好,很高興你有它的工作!請張貼您的解決方案以及TruncationOptions的參考,我從來沒有使用它! – danii 2013-03-07 11:43:08