0

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

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

TLFTextField 有一个 getTextFormat 和 setTextFormat 函数,但它们都非常有问题。getTextFormat 仅在您将 selectable 属性更改为 true 时才有效,否则会生成空对象错误。当 TextFormat 对象的某些属性不为空时,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?

4

2 回答 2

0

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

于 2011-11-04T20:18:27.017 回答
0

在简单的情况下,这有效

var format:TextLayoutFormat = textField.textFlow.hostFormat as TextLayoutFormat;
format.fontFamily = fontFamily;
textField.textFlow.hostFormat = format;
textField.textFlow.flowComposer.updateAllControllers();
于 2013-11-01T12:59:51.877 回答