subrat71
subrat71

Reputation: 348

Fix the label width on text length increase

I have a label, a textInput and a button. On button click text of textInput assign to text of label. Width of the label is 50.

But if the textInput length is greater than 8 then the label appears like below image

My OutPut

Objective:- I want my output as below image

Expected OutPut

And my code looks like

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    width="400" height="200">

    <fx:Declarations>

    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import com.greensock.TweenLite;
            import com.greensock.TweenMax;
            protected function btn_clickHandler(event:MouseEvent):void
            {
                lbl.text = inputTxt.text;
                trace(lbl.text.length,lbl.width);
                if(lbl.text.length > 8)
                {
                                  //need some code here.....
                    }
            }

        ]]>
    </fx:Script>


    <s:BorderContainer height="100%" width="100%" backgroundColor="green" />
    <s:HGroup gap="10">
        <s:TextInput id="inputTxt"/>
        <s:Button id="btn" click="btn_clickHandler(event)"/>
    </s:HGroup>
    <s:Label id="lbl" width="50" top="50"/>
</s:WindowedApplication>

Upvotes: 0

Views: 492

Answers (1)

Andrey Popov
Andrey Popov

Reputation: 7510

I think maxDisplayedLines will help you: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/supportClasses/TextBase.html#maxDisplayedLines

It should automatically truncate the text for you (add ... at the end). Just set this to 1.

Upvotes: 2

Related Questions