0

我的 Flex 应用程序中有许多标签,它们的“truncateToFit”属性设置为 true。问题是,它不会在任何截断文本的末尾显示“...”,而是显示空值。

即,如果我的标签文本是:“Hello Stackoverflow!” 我可能希望我的标签看起来像这样:

“你好斯塔科夫……”

相反,它显示

“你好 Stackovnull”

任何帮助都会很有用!

截断的外观示例

编辑: - 示例代码:

<mx:HBox width="200" ... >
   <mx:Label maxWidth="150" truncateToFit="true" text="Really long text.Really long text.Really long text.Really long text.Really long text" />
</mx:HBox>
4

6 回答 6

2

哈哈!我找到了解决方案。对不起,伙计们 - 可能是我缺乏信息,这让你们很难为 m 调试 :(

所以,无论如何 - 事实证明我有一个外部 resourceModule swf,我的应用程序加载它以从中获取本地化语言数据等 - 该文件不包含有关为截断显示哪些文本的一些数据(即“...”)所以它改为显示'null'。我将该数据添加到 Resource swf 中,并且一切都按预期工作。

感谢一百万试图帮助我的家伙。;)

于 2009-04-21T13:37:30.430 回答
1

问题是默认的 Flex 资源包之一未包含在您编译的本地化文件中。有关详细说明和修复,请参见此处:http: //deniszgonjanin.posterous.com/flex-truncation-null-error-fix

于 2010-09-02T21:38:54.867 回答
0

我刚刚尝试了您的示例代码,它运行良好。你确定不是别的吗?

于 2009-04-17T04:50:32.010 回答
0

所以我去嵌入了我自己的字体,它可以很好地截断,没有任何特别的问题。我不确定您是如何嵌入字体的,但这种方法对我有用。如果您正在做一些完全不同的事情,请在您的帖子中指定。

// Cannot name the font as one that already exists!
[Embed(source="Anonymous.ttf", fontFamily="myAnon")]
private var fontA : Class;

[Embed(source="HGRSGU.TTC", fontFamily="myFont")]
private var fontB : Class;

//...I have some code here that switches the font
var obj : Object = truncateMe.getStyle("fontFamily");
if (obj == "myAnon")
  truncateMe.setStyle("fontFamily", "myFont");
else
  truncateMe.setStyle("fontFamily", "myAnon");

<!-- My Label -->
<mx:Label maxWidth="150" truncateToFit="true" id="truncateMe"
    text="Something really long goes here" fontFamily="myFont" fontSize="20"/>
于 2009-04-18T05:30:25.120 回答
0

如果使用多个语言环境,请确保将“en_US”添加到您的语言环境链。例如:resourceManager.localeChain = ['pt_BR', 'en_US'];

在以下位置找到解决方案:http: //blog.flexexamples.com/2008/01/26/truncate-text-in-the-flex-label-control-using-the-truncatetofit-property/

查找 Leandro 的帖子

于 2009-11-05T03:22:16.943 回答
0

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

    }
}
于 2010-07-06T15:18:53.477 回答