我有這個問題今天(3H),這是太多了一點問題,因爲這個巨大的戰鬥。無論如何,上述提示都沒有解決我的問題。我嘗試了一切。我最終做了我自己的課程,它擴展了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;
}
}
}
請完全按照原樣添加源代碼(這看起來像一個錯誤之一)。標籤的文本是兩個字符串的串聯嗎?另外,你有`maxWidth`設置? – dirkgently 2009-04-14 16:14:58
添加的代碼 - 我很確定這與我的代碼無關。這似乎可能是一個配置問題? – 2009-04-14 17:14:20