Skip to main content
Participant
February 2, 2011
Question

TextLayoutFormat & TLFTextField

  • February 2, 2011
  • 1 reply
  • 1102 views

Hi All,

I try to change TextLayoutFormat of TLFTextField. I can change format only after create and adding TLFTextField to stage. Then I try to call getChild() and change it but nothing has happens. Here is a part of my code. "text_child" is TLFTextField on Stage.

//---------------------------

import fl.text.TLFTextField;

import flashx.textLayout.formats.TextLayoutFormat;

import flashx.textLayout.elements.TextFlow;

var text_create : TLFTextField = new TLFTextField();

addChild(text_create);

text_child.text = "text child";

text_create.text = "text create";

var myFormat:TextLayoutFormat = new TextLayoutFormat();

myFormat.color = 0x336633;

myFormat.fontSize = 24;

var myTextFlow : TextFlow;

myTextFlow = text_create.textFlow;

myTextFlow.hostFormat = myFormat;

myTextFlow.flowComposer.updateAllControllers();

myTextFlow = text_child.textFlow;

myTextFlow.hostFormat = myFormat;

myTextFlow.flowComposer.updateAllControllers();

This topic has been closed for replies.

1 reply

February 3, 2011

When Flash Pro puts a TLFTextField on the stage (aka, "text_child"), all the character attributes, like color, are set on spans, not on the TextFlow. So, when you set the color on the hostFormat, you're really setting the color on the TexFlow, unless that value is overridden somewhere, which it is. To do what I think you're trying to do, do the following:

var textFmt:TextFormat = new TextFormat();

textFmt.color = 0x336633;

text_child.setTextFormat(textFmt);

Alternatively, you could traverse all the leaves of the TextFlow, and set the TextLayoutFormat on them, but I suspect you want to just change the color, and not change all the other values to their defaults, which is what you did with the hostFormat.

The reason your code works for the "text_create" object is that there is no other formatting applied to the TextFlow -- you just set the text. So, setting the color on the TextFlow trickles down to each of the leaves since they don't override the color.

Hope that helps.

February 3, 2011

I thought I'd add one more suggestion here: Try tracing out the tlfMarkup on your stage object. I think that'll help you see the overrides I'm talking about.

trace(text_child.tlfMarkup);