【问题标题】:finding last character shown on a flex spark label查找 flex spark 标签上显示的最后一个字符
【发布时间】:2012-01-31 16:52:50
【问题描述】:

在火花标签的所有选项中,没有一个告诉我文本被截断时显示的最后一个字符,有没有办法做到这一点?

【问题讨论】:

    标签: actionscript-3 apache-flex flex4.5


    【解决方案1】:

    对于 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);
                }
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      这里是 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>
      

      【讨论】:

      • 返回标签文本属性中的最后一个字符,无论它是否可见,我想知道在它得到时出现在末尾的“...”之前的字符被截断。
      • 我已经编辑了代码......并且只需添加一行来修剪 textinput 中的文本......现在你会得到正确的答案。
      • 仍然是相同的结果,请记住我问的是火花标签,而不是 mx textinput。
      • 现在可以了吗?我已将 textinput 更改为 Label ..... 很抱歉,因为我的 PC 中没有安装 FLEX 4,所以我不能给你 spark 标签的结果.. 但我确信类似的方法也用于那个.
      • 好吧,我确实在标签上测试过,结果如我所说,是整个文本属性中的最后一个字符,而不是显示的最后一个字符。也许这是迁移到 spark 时取出的那些东西之一。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 1970-01-01
      • 2023-03-06
      • 2022-10-13
      • 2022-09-27
      • 1970-01-01
      • 2015-10-31
      相关资源
      最近更新 更多