我要做的就是获取 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?