1

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

2 に答える 2

1

幸い、TLFTextfieldpaddingTopを使用すると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);

お役に立てれば!

于 2013-03-07T00:45:27.810 に答える
0

この領域を別のクリップでマスクして、はみ出したテキストを隠すことができます。

于 2013-03-06T18:45:24.987 に答える