Modify TLF Text Field properties that is on stage

1.9k Views Asked by At

I have a TLF Text field on the stage. I am trying to test this out in simple flash document.

My code takes in some xml that I parse. The xml will vary and will not always change all the properties of the text field. For instance in one case I only want to change the size of the font. In another case I only want to change the alignment of the font.

I am using TLF Text fields because we will translating into Arabic and I already have gotten Right to Left text working with them.

These are some properties I will need to edit in code:

  • Font Size
  • Font
  • Alignment
  • Leading
  • Bold, Italic, Underline (weight)

Any coding help would be great. I have seen ideas out there for text flow and text layout but I am obviously not using it correctly because I can't get it to work.

1

There are 1 best solutions below

0
On

Long ago before I give up and stop using TLF fields. I have a project that requests dynamic addind and removing tlf fileds from/to stage. This is a code from this project:

This will generate default format dynamically

        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 );

member m_textFlow holds a ref to TLF field. To add and remove elements use m_textFlow.addChild( p ); where p is paragraph element see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLayout/elements/ParagraphElement.html

To change the FontSize and color an element for example :

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;

...

Maybe this can help you.