1

It is possible set an maximum number of lines to been showd on TLFTextField? So I have an text than I don't wanna that display all over the text, just the 3 first lines visibles. How can I configure that?

This is what I have yet:

         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();
David Fortunato
  • 769
  • 1
  • 6
  • 19

2 Answers2

1

Luckily, using TLFTextfield we have properties like paddingTop and paddingBottom of text and total textHeight in pixels. Knowing also the total numLines of text in the textfield, we can work out how many pixels in height the number of lines we want to show would take.

EDIT: I've noticed that for some rather smalllish widths of the textfield the numLines property doesn't hold the expected value... I don't know if this might be a BUG, but reading it before the calculation seems to fix it.

Try this (put these lines after all your code) :

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

Hope this helps!

danii
  • 5,553
  • 2
  • 21
  • 23
  • Thanks for the answer, and this will work if I don't need to use any image on my "textfield", but I need to show an image align on the left of text and the text must be lesser than image, so with your solution this will cut my image too. But I guess I found a solution using TruncationOptions (that I just found it after a long hours ago), when I resolve that I'll post my solution. Thanks anyway, this will help for other cases :) – David Fortunato Mar 07 '13 at 10:33
  • Great, glad you got it working! please post your solution as well for reference on TruncationOptions, I have never used it! – danii Mar 07 '13 at 11:43
0

You could mask the area with another clip to hide overflowing text.

kingdomcreation
  • 659
  • 4
  • 10