我今天(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;
}
}
}