Skip to main content
A_Shiyaz
Known Participant
February 5, 2010
Answered

How to update text or change text in TLF?

  • February 5, 2010
  • 2 replies
  • 2067 views

Hi,

I am unable to update the text within a TLF. This must be pretty basic, but am overlooking something.

This is the pseudo code:

pg_xml = new XML(str);
textFlow = TextConverter.importToFlow(pg_xml, TextConverter.TEXT_LAYOUT_FORMAT);
var tlf_sp = new Sprite();
textFlow.flowComposer.addController(new ContainerController(tlf_sp, width, height));
tlf_sp.x = posx;
tlf_sp.y = posy;
textFlow.flowComposer.updateAllControllers();
addChild(tlf_sp);

Elsewhere, the text needs to be updated:

pg_xml = new XML(str);
textFlow = TextConverter.importToFlow(pg_xml, TextConverter.TEXT_LAYOUT_FORMAT);
//TODO: figure out how to update text! updateAllControllers doesn't work.
//textFlow.flowComposer.compose(); //-- Didn't work.
//textFlow.flowComposer.updateAllContainers(); //-- Though this couldn't be used, I was just trying out, but didn't work either.
textFlow.flowComposer.updateAllControllers();

TLF version used: 4.0.0.13895

I just need to update the contents of a TLF rather than recreating a new textflow. Any help will be much appreciated.

Regards,

Shiyaz

This topic has been closed for replies.
Correct answer GordonSmith

If you are importing, the importing process always produces a new TextFlow. You can't import into an existing TextFlow.

Gordon Smith

Adobe Flex SDK Team

2 replies

Participating Frequently
February 5, 2010

Other TLF classes like the TextContainerManager, allow you to create an instance and then set its plain text or its textFlow, so you don't have to keep creating new instances of TextContainerManager when what you want to display changes. But, conceptually, a TextFlow is a class representing what you want to display, not a class for displaying it.

Gordon Smith

Adobe Flex SDK Team

GordonSmithCorrect answer
Participating Frequently
February 5, 2010

If you are importing, the importing process always produces a new TextFlow. You can't import into an existing TextFlow.

Gordon Smith

Adobe Flex SDK Team

February 5, 2010

Or you can hook up the new flow to the old ContainerController:

pg_xml = new XML(str);

var containerController:ContainerController = textFlow.flowComposer.getControllerAt(0);         

textFlow = TextConverter.importToFlow(pg_xml, TextConverter.TEXT_LAYOUT_FORMAT);

textFlow.flowComposer.addController(containerController);

textFlow.flowComposer.updateAllControllers();

This is assuming you only have the one ContainerController. For a more in-depth example of this kind of thing, take a look at changeContent() in TextLayoutEditorCanvas.mxml in our sample code in this blog post: http://blogs.adobe.com/tlf/2009/12/new-and-updated-tlf-samples.html