Skip to main content
Participant
February 19, 2009
Answered

Problem with creating a container with single text line

  • February 19, 2009
  • 1 reply
  • 374 views
Hi~
I'm crushed with a following problem.
Problem: I need to create a container with a single text line. As i learn from the TLF API, there's no way to do that so it left only a way that's like this:

//Assuming textFlow object is create
var container:Sprite = new Sprite();
var width:Number = 500; // it's specified value
var height:Number = 300; // just estimating it's enought for a normal single line height
var controller:DisplayObjectContainerController = new DisplayObjectContainerController(container, width, height);
controller.verticalScrollPolicy = ScrollPolicy.OFF;

textFlow.flowComposer.addController(controller); textFlow.flowComposer.composeContainer(textFlow.flowComposer.getControllerIndex(controller));

// find top first line in the created container
var textFlowLine:TextFlowLine= textFlow.flowComposer.findLineAtPosition(controller.absoluteStart, false);
var calLineHeight:Number = textFlowLine.textHeight+8; // here 8 is just a test value
controller.setCompositionSize(width, calLineHeight);
textFlow.flowComposer.updateContainer(_textFlow.flowComposer.getControllerIndex(controller));


In this way, it first calculate first line height giving enough space to the controller
and composing, after that it adjust the container height again then updates.
It's so much overhead i guess

So anybody have more simple or right way to do?
This topic has been closed for replies.
Correct answer rdermer

Regarding a single line. I think you could set the lineBreak property on the TextFlow to "explicit". In that case lines only break at newlines and pargraph ends.

If you don't want editability have a look at the TextLineFactory APIs. Set NaN in the width/height of the bounds and it gets filled in. This is a lighter weight way to create TextLines.

Using full TextFlows as in your code take a look at the DisplayObjectContainerControllers compositionHeight and compositionWidth properties. You still want to use explicit line breaks.

Hope that helps!
Richard

1 reply

rdermerCorrect answer
Adobe Employee
February 19, 2009

Regarding a single line. I think you could set the lineBreak property on the TextFlow to "explicit". In that case lines only break at newlines and pargraph ends.

If you don't want editability have a look at the TextLineFactory APIs. Set NaN in the width/height of the bounds and it gets filled in. This is a lighter weight way to create TextLines.

Using full TextFlows as in your code take a look at the DisplayObjectContainerControllers compositionHeight and compositionWidth properties. You still want to use explicit line breaks.

Hope that helps!
Richard