Skip to main content
AdrianParr
Known Participant
January 6, 2010
Answered

Accessing the 'text' in a TextFlow instance?

  • January 6, 2010
  • 2 replies
  • 655 views

How do I actually access the textual content of a TextFlow object?

When there is a single SpanElement in the TextFlow then I am able to use ...

mySpan.text

But if I have added multiple SpanElements to the ParagraphElement then how do I get the entire textual content so that I can store it in a String variable.

I am also having problems accessing the entire text when the user has pasted in to an editable field, I presume this is because of multiple SpanElements being created.

Is there anything that is the equivalent to the old ...

myTextField.text

Thanks in advance,

Adrian

This topic has been closed for replies.
Correct answer

TextFlow (and all FlowElements) has a getText method.

2 replies

AdrianParr
Known Participant
January 7, 2010

getText() is a method of the FlowGroupElement class, of which TextFlow is a descendant.

Correct answer
January 6, 2010

TextFlow (and all FlowElements) has a getText method.

AdrianParr
Known Participant
January 7, 2010

Hi Alan,

Thank you so much for your help!!!

Just for the record, here is a working example ...

import flashx.textLayout.container.*;
import flashx.textLayout.elements.*;
import flashx.textLayout.edit.*;

var config:Configuration = new Configuration();
config.manageEnterKey = false;

var textFlow:TextFlow = new TextFlow(config);

var para:ParagraphElement = new ParagraphElement();

var span1:SpanElement = new SpanElement();
span1.text = "Hello ";
span1.fontSize = 12;

var span2:SpanElement = new SpanElement();
span2.text = "World";
span2.fontSize = 16;

para.addChild(span1);
para.addChild(span2);
textFlow.addChild(para);

var cc:ContainerController = new ContainerController(this, 550, 400);
textFlow.flowComposer.addController(cc);
textFlow.flowComposer.updateAllControllers();

trace("textFlow.numChildren:"+textFlow.numChildren);
// OUTPUT: 1

trace("para.numChildren:"+para.numChildren);
// OUTPUT: 2

trace("textFlow.getText():"+textFlow.getText());
// OUTPUT: Hello World