0

我在舞台上有一个 TLF 文本字段。我正在尝试在简单的 Flash 文档中对此进行测试。

我的代码接受了一些我解析的 xml。xml 会有所不同,并且不会总是更改文本字段的所有属性。例如,在一种情况下,我只想更改字体的大小。在另一种情况下,我只想更改字体的对齐方式。

我正在使用 TLF 文本字段,因为我们将翻译成阿拉伯语,并且我已经获得了从右到左的文本使用它们。

这些是我需要在代码中编辑的一些属性:

  • 字体大小
  • 字体
  • 结盟
  • 领导
  • 粗体、斜体、下划线(粗体)

任何编码帮助都会很棒。我已经看到了关于文本流和文本布局的想法,但我显然没有正确使用它,因为我无法让它工作。

4

1 回答 1

0

很久以前,在我放弃并停止使用 TLF 字段之前。我有一个项目要求动态添加并从/到阶段删除 tlf 文件。这是该项目的代码:

这将动态生成默认格式

        var config:Configuration    = new Configuration();
        var defTextFormat:  TextLayoutFormat = new TextLayoutFormat();
        defTextFormat.textAlign   = TextAlign.LEFT;
        defTextFormat.fontFamily  = m_strFontName;
        defTextFormat.fontSize    = m_nFontSize;
        defTextFormat.fontWeight  = FontWeight.BOLD
        defTextFormat.paddingLeft = 3;
        defTextFormat.paddingTop  = 3;
        defTextFormat.paragraphStartIndent = 3;
        defTextFormat.paragraphSpaceBefore = 3;

        config.defaultLinkActiveFormat  = defTextFormat;
        config.defaultLinkHoverFormat   = defTextFormat;
        config.defaultLinkNormalFormat  = defTextFormat;
        config.textFlowInitialFormat    = ITextLayoutFormat( defTextFormat );

        m_textFlow = new TextFlow( config );

成员 m_textFlow 持有对 TLF 字段的引用。要添加和删除元素,请使用 m_textFlow.addChild( p ); 其中 p 是段落元素,请参阅:http ://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLayout/elements/ParagraphElement.html

要更改 FontSize 并为元素着色,例如:

var _p:ParagraphElement = ParagraphElement( m_textFlow.getChildAt( iChild ) );
for ( var iParChild: uint = 0; iParChild < _p.numChildren; ++iParChild )
{
   _p.getChildAt( iParChild ).color = color;
       _p.getChildAt( iParChild ).fontSize = nRatio;

...

也许这可以帮助你。

于 2012-10-11T08:07:20.607 回答