修复文本长度增加时的标签宽度

时间:2014-06-03 08:00:10

标签: actionscript-3 flex flex4

我有一个标签,一个textInput和一个按钮。在按钮上单击textInput的文本分配给标签文本。标签的宽度为50。

但是如果textInput长度大于8,则标签显示如下图像

My OutPut

目标: - 我希望输出如下图所示

Expected OutPut

我的代码看起来像

<?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>

1 个答案:

答案 0 :(得分:2)

我认为maxDisplayedLines会对您有所帮助:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/supportClasses/TextBase.html#maxDisplayedLines

它会自动为您截断文本(最后添加...)。只需将其设置为1。

相关问题