Flash - 无法获取 TLFTextField 的 TextLayoutFormat
我想要做的就是获取 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是 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.
在简单的情况下这有效
In simple case this works