Flash - установить максимальное количество строк в TLFTextField

Можно ли установить максимальное количество строк, которые будут показаны на TLFTextField? Поэтому у меня есть текст, который я не хочу отображать по всему тексту, только видимые 3 первые строки. Как я могу настроить это?

Это то, что у меня еще есть:

         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();

2 ответа

К счастью, используя TLFTextfield, у нас есть такие свойства, как paddingTop а также paddingBottom текста и всего textHeight в пикселях. Зная также общее numLines текста в текстовом поле, мы можем определить, сколько пикселей в высоту займет количество строк, которые мы хотим показать.

РЕДАКТИРОВАТЬ: я заметил, что для некоторых довольно небольших ширины текстового поля 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);

Надеюсь это поможет!

Вы можете замаскировать область другим клипом, чтобы скрыть переполненный текст.

Другие вопросы по тегам