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>
對於spark標籤,您可以在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);
}
}
}
}
返回標籤文本屬性中的最後一個字符,無論它是否可見,我想知道在截斷時出現在末尾的「...」之前的字符。 – 2012-02-07 15:23:38
我編輯了代碼..並且只是添加了一行修剪textinput中的文本......現在您將得到正確的答案。 – 2012-02-08 04:26:28
仍然是相同的結果,請記住,我詢問的是spark標籤,而不是mx textinput。 – 2012-02-08 16:26:27