Flash - 无法获取 TLFTextField 的 TextLayoutFormat

发布于 2024-12-13 09:41:35 字数 998 浏览 0 评论 0原文

我想要做的就是获取 TLFTextField 的格式属性并将其应用到另一个 TLFTextField。使用经典的 TextField 很简单:

var textFormat:TextFormat = text1.getTextFormat();
text2.setTextFormat(textFormat);

TLFTextField 有 getTextFormat 和 setTextFormat 函数,但它们都有很多错误。 getTextFormat 仅在将 selectable 属性更改为 true 时才有效,否则会生成空对象错误。当 TextFormat 对象的某些属性不为 null 时,setTextFormat 会生成 NaN 错误。

TextLayoutFormat 对象应该用于代替 TLFTextFields。您可以通过执行以下操作来设置对象:

var text1:TLFTextField = new TLFTextField();
var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
var textFlow:TextFlow = text1.textFlow;
textFlow.hostFormat = textLayoutFormat;
textFlow.flowComposer.updateAllControllers();

但是,我现在无法弄清楚如何从 text1 中“获取”TextLayoutFormat。一个人提出了以下建议:

textLayoutFormat = ((text1.textFlow.getChildAt(0) as ParagraphElement).getChildAt(0) as SpanElement).computedFormat as TextLayoutFormat;

但这只是返回 null。有谁知道如何获取 TextLayoutFormat 以便我可以将其应用到另一个 TLFTextField 吗?

All I want to do is get the formatting properties of a TLFTextField and apply it to another TLFTextField. This was simple using the classic TextField:

var textFormat:TextFormat = text1.getTextFormat();
text2.setTextFormat(textFormat);

TLFTextField has a getTextFormat and setTextFormat function, but they are both very buggy. getTextFormat only works if you change the selectable property to true, otherwise it generates a null object error. setTextFormat generates a NaN error when some of the properties of the TextFormat object are not null.

The TextLayoutFormat object is supposed to be used instead for TLFTextFields. You set the object by doing the following:

var text1:TLFTextField = new TLFTextField();
var textLayoutFormat:TextLayoutFormat = new TextLayoutFormat();
var textFlow:TextFlow = text1.textFlow;
textFlow.hostFormat = textLayoutFormat;
textFlow.flowComposer.updateAllControllers();

However, I cannot figure out how to 'get' the TextLayoutFormat from text1 now. One person suggested the following:

textLayoutFormat = ((text1.textFlow.getChildAt(0) as ParagraphElement).getChildAt(0) as SpanElement).computedFormat as TextLayoutFormat;

But this just returned null. Does anyone know how to get the TextLayoutFormat so I can apply it to another TLFTextField?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月牙弯弯 2024-12-20 09:41:35

您使用的是 Flex 还是 Flash?我最近也因 TLF 而感到头疼。此页面对我来说是一个很好的参考:http://flashthusiast.com/2010/05/05/getting-started-with-the-tlftextfield-class-in-actionscript-3-0-and-flash-cs5/您是否在文本之前设置文本格式?我已经这样做了,但没有遇到你的空问题。

Are you using Flex or Flash? I've recently had my own headaches with TLF. This page was a good reference for me: http://flashthusiast.com/2010/05/05/getting-started-with-the-tlftextfield-class-in-actionscript-3-0-and-flash-cs5/ Are you setting the text format prior to the text? I've done that and haven't had your null problem.

我只土不豪 2024-12-20 09:41:35

在简单的情况下这有效

var format:TextLayoutFormat = textField.textFlow.hostFormat as TextLayoutFormat;
format.fontFamily = fontFamily;
textField.textFlow.hostFormat = format;
textField.textFlow.flowComposer.updateAllControllers();

In simple case this works

var format:TextLayoutFormat = textField.textFlow.hostFormat as TextLayoutFormat;
format.fontFamily = fontFamily;
textField.textFlow.hostFormat = format;
textField.textFlow.flowComposer.updateAllControllers();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文