0

私がやりたいことは、TLFTextField の書式設定プロパティを取得し、それを別の TLFTextField に適用することだけです。これは、従来の TextField を使用すると簡単でした。

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

TLFTextField には getTextFormat と setTextFormat 関数がありますが、どちらも非常にバグがあります。getTextFormat は、selectable プロパティを true に変更した場合にのみ機能します。それ以外の場合は、null オブジェクト エラーが生成されます。setTextFormat オブジェクトの一部のプロパティが 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を返しました。別の TLFTextField に適用できるように TextLayoutFormat を取得する方法を知っている人はいますか?

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 に答える