Answered
Possible bug in TextLayout
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).
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).
