2012-10-10 44 views
0

我在舞台上有TLF文本字段。我正试图在简单的Flash文档中测试这一点。修改舞台上的TLF文本字段属性

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

我使用的是TLF文本字段,因为我们将翻译成阿拉伯语,而且我已经获得了从右到左的文本与他们合作。

这些都是一些特性,我需要在代码编辑:

  • 字体大小
  • 字体
  • 对准
  • 领导
  • 粗体,斜体,下划线(重量)

任何编码帮助将是伟大的。我已经看到了有关文本流和文本布局的想法,但我显然没有正确使用它,因为我无法使它正常工作。

回答

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

要更改字号和颜色元素,例如:

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; 

...

也许这可以帮助你。