Flex/Actionscript truncateToFit 在标签组件上
我的 Flex 应用程序中有许多标签,它们的“truncateToFit”属性设置为 true。 问题是,在任何截断文本的末尾不是显示“...”,而是显示 null。
即,如果我的标签文本是:“Hello Stackoverflow!” 我可能希望我的标签看起来像这样:
“Hello Stackov...”
相反,它显示
“Hello 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
哈哈! 我找到了解决方案。 抱歉,各位 - 可能是我缺乏信息,导致你们很难调试 m :(
所以,无论如何 - 事实证明,我有一个外部资源模块 swf,我的应用程序加载了该资源以从中获取本地化语言数据等 - 此文件不包含有关截断显示的文本的一些数据(即“...”),因此它显示为“null”,我将该数据添加到资源 swf 中,一切都按预期工作
。试图帮助我的人;)
Ha ha! I found the solution. Sorry guys - It was probably my lack of information which made it hard for you guys to debug for m :(
So, anyway - It turns out I had an external resourceModule swf which my application loaded to get localised language data etc from - This file didn't include the some data about what text to display for the truncation (i.e. '...') and so it instead displayed 'null'. I added that data to the Resource swf and it's all working as expected.
Thanks a million for trying to help me out guys. ;)
问题是默认的 Flex 资源包之一未包含在您编译的本地化文件中。 请参阅此处了解详细说明和修复:
http://deniszgonjanin.posterous.com/flex-truncation-null-error-修复
The problem is that one of the default Flex resource bundles is not included in your compiled localization files. See here for the detailed explanation and fix:
http://deniszgonjanin.posterous.com/flex-truncation-null-error-fix
我刚刚尝试了你的示例代码,效果很好。 你确定这不是别的东西吗?
I just tried your example code and it worked fine. Are you sure its not something else?
因此,我嵌入了自己的字体,它可以很好地截断,没有任何特殊问题。 我不确定你是如何嵌入字体的,但这种方法对我有用。 如果您正在做完全不同的事情,请在您的帖子中注明。
So I went and embedded a font of my own and it truncates nicely without any particular issue. I'm not sure how you are embedding your font but this method worked for me. If you are doing something completely different then please specify in your post.
如果使用多个语言环境,请确保将“en_US”添加到您的语言环境链中。 例如:
ResourceManager.localeChain = ['pt_BR', 'en_US'];
找到解决方案:http://blog.flexexamples.com/2008/01/26/truncating-text-in-the-flex-label-control-using-the-truncatetofit-property/
寻找 Leandro 的发帖
If working with multiple locales, make sure you add 'en_US' to your localeChain. E.g.:
resourceManager.localeChain = ['pt_BR', 'en_US'];
Found solution at: http://blog.flexexamples.com/2008/01/26/truncating-text-in-the-flex-label-control-using-the-truncatetofit-property/
Look for Leandro's posting
今天(3小时)我为这个问题进行了一场激烈的斗争,对于像这样的小问题来说,这实在是太多了。 无论如何,以上提示都没有解决我的问题。 我都试过了。 我最终创建了自己的类,它扩展了 mx.controls.Label 类。 实施如下。 请随意在您的项目中使用它。 请注意,使用此选项时,您应该在 mxml 中禁用 truncateToFit。 否则,“null”字符串将被附加到您的文本中,并且不会进行截断。
代码:
I had a huge fight with this issue today (3h), which is way too much for a little issue as this. Anyway, none of the above tips solved my problem. I tried it all. I ended up doing my own class, which extends the
mx.controls.Label
class. The implementation is below. Feel free to use it in your projects. Please note that you should disable the truncateToFit in your mxml when using this one. Else the "null" string will be appended to your text and no truncation will be made.Code: