查找flex spark标签上显示的最后一个字符



在spark标签的所有选项中,没有一个选项告诉我文本被截断时显示的最后一个字符,有什么方法可以实现这一点吗?

对于spark Label,您可以在updateDisplayList绘制控件后捕获textLines属性。

package frm.ria.signoff.views.components
{
    import flash.text.engine.TextLine;
    import spark.components.Label;
    import mx.core.mx_internal;
    public class LastShownCharLabel extends Label
    {
        [Bindable]
        public var lastChar:String;
        protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth,unscaledHeight);
            if(mx_internal::textLines.length>0)
            {
                var charsInfirstLine:int = TextLine(mx_internal::textLines[0]).rawTextLength;
                if(text) lastChar = text.charAt(charsInfirstLine-1);
            }
        }
    }
}

这里是它的mxml文件。请执行以下代码。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
        public function onClick():void
        {
            lbl.text = StringUtil.trim(lbl.text);
            output.text = lbl.text.charAt(lbl.text.length -1);
        }
    ]]>
</mx:Script>
<mx:VBox>
    <mx:Label id="lbl" text="Sagar    "/>
    <mx:Button click="{onClick();}" label="Click" />
    <mx:TextInput id="output" />
</mx:VBox>
</mx:Application>

最新更新