私は今日 (3 時間) この問題で大喧嘩をしました。とにかく、上記のヒントのどれも私の問題を解決しませんでした。私はそれをすべて試しました。クラスを拡張する独自のクラスを作成することになりましたmx.controls.Label
。実装は以下。プロジェクトで自由に使用してください。これを使用する場合は、mxml で truncateToFit を無効にする必要があることに注意してください。それ以外の場合、「null」文字列がテキストに追加され、切り捨ては行われません。
コード:
package com.feijk.UI {
import mx.controls.Label;
/**
* An extension for mx.controls.Label to truncate the text and show
* a tooltip with the full-length content. This sub-class is meant to be
* used when the regular truncateToFit does result in a "null" appendix
* on the string instead of the "...". In order for this to work, I used
* the following parameters in my mxml:
*
* - truncateToFit = false
* - maxWidth = set
* - width = set
*
*
* @author Tomi Niittumäki // Feijk Industries 2010
* @NOTE: Feel free to use! :)
*/
public class FLabel extends Label{
// define the truncation indicator eg. ...(more) etc.
private const TRUNCATION_INDICATOR:String = new String("...");
/**
* Constructor
*/
public function FLabel(){
super();
}
/**
* The overriding method, which forces the textField to truncate
* its content with the method truncateToFit(truncationIndicator:String)
* and then supers the tooltip to be the original full-length text.
*/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth, unscaledHeight);
//trace("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: "+textField.text);
textField.truncateToFit(TRUNCATION_INDICATOR);
super.toolTip = text;
}
}
}