Skip to main content
Inspiring
February 13, 2009
Answered

Possible bug in TextLayout

  • February 13, 2009
  • 1 reply
  • 487 views
I've got a simple quiz that needs to be ported from FTE to the TextLayout Framework. To get something approximating TextField.autoSize, I use an ample initial value for height, and then use setCompositionSize to crop the DisplayObjectContainer back down to it's correct size. I have a bunch of Choices which are all parented to a Sprite. I measure that Sprite to put the results under the Choices. In the Choice class, everything looks normal. If I trace the boundaries with the drawing API, they are where I expect them.

The problem is the parent Sprite that contains all the Choice instances. Its height hasn't been updated to reflect setCompositionSize.

Here are the relevant code snippets:

//This class creates each Choice:
_choiceSprite = new Sprite();
_choiceSprite.x = 30;
addChild(_choiceSprite);

var choiceXML:XML = new XML("<TextFlow characterFormat='{choiceCF}' containerFormat='{offsetContainerFormat}'><p></p></TextFlow>");
choiceXML.prependChild(_formats);
choiceXML.p.appendChild(UtilityFunctions.stripTag(_xml));

var choiceFlow:TextFlow = TextFilter.importToFlow(choiceXML, TextFilter.TEXT_LAYOUT_FORMAT);
var choiceContainer:IContainerController = new DisplayObjectContainerController(_choiceSprite, 700, 700);
choiceFlow.flowComposer.addController(choiceContainer);
choiceFlow.flowComposer.updateContainer(choiceContainer);
choiceContainer.setCompositionSize(700, choiceContainer.contentHeight);

//This draws a rectangle the size of contentHeight. It is correctly ignoring the 700px initial height.
with (graphics) {
beginFill(0x000000, 0);
drawRect(0, 0, _choiceSprite.x + _choiceSprite.width, _choiceSprite.y + _choiceSprite.height);
}


//Here is the code that positions the feedback under the choices. Note that in this context, _choiceSprite contains ALL the Choice instances. (In the Choice code above, a similarly-named variable contains the TextFlow).
_feedbackSprite.x = _choiceSprite.x;
_feedbackSprite.y = _choiceSprite.y + _choiceSprite.height + spacing * 2;


For some reason, _choiceSprite is over 700 pixels tall, even though its children are nowhere near that size. If I change the initial value in the Choice class, _feedbackSprite moves accordingly (even though the choices have already been resized).
This topic has been closed for replies.
Correct answer robin_briggs
I think there may be a misunderstanding here. The compositionHeight is an input parameter -- its the area you want the text to fit. How big the text will actually be has to do with how much text there is. The height of the Sprite is a function of what display objects are in it. If there is a lot of text, then after you have called updateAllContainers the Sprite will be holding a lot of TextLines, and its height will be the height of the lines. If there is less text, then there will be less lines, and the height of the Sprite will be less.

1 reply

robin_briggsCorrect answer
Adobe Employee
February 18, 2009
I think there may be a misunderstanding here. The compositionHeight is an input parameter -- its the area you want the text to fit. How big the text will actually be has to do with how much text there is. The height of the Sprite is a function of what display objects are in it. If there is a lot of text, then after you have called updateAllContainers the Sprite will be holding a lot of TextLines, and its height will be the height of the lines. If there is less text, then there will be less lines, and the height of the Sprite will be less.