I have two linked containers. When I update the compositionSize on one of them, they both change. They share the same textFlow, so my code is simply:
- I would expect this only to update the width of the specified controller/container pair, but it operates on both of them.
What am I doing wrong?
Many thanks in advance.
Jude Fisher / JcFx.Eu
I'm working with Air 2.0, and version of the TLF which shipped with Flex 4.1.0.
My code is a bit distributed across various objects in a fairly complex solution but here are the relevant sections.
There are two separate views, each of which creates its own controller:
protected var containerController:ContainerController;
protected function renderStoryView():void
containerController = new ContainerController(textHolder, this.width, this.height);
containerController.horizontalScrollPolicy = ScrollPolicy.OFF;
containerController.verticalScrollPolicy = ScrollPolicy.OFF;
protected function createTextHolder():void
textHolder = addChild(new UIComponent()) as UIComponent;
protected function updateStoryFlowControllers():void
Normally each view has its own textFlow associated with it, but in the case of two linked views, they share the same text Flow. The code which does that is here:
View.StoryFlow = ModelTextFrame.MyParentStory.StoryFlow;
var parentController:TextFrameController = MySpreadController.GetTextFrameBySelf(ModelTextFrame.PreviousTextFram e);
View.StoryFlow = parentController.View.StoryFlow; // This View now has the same TextFlow as another one.
This works fine, and the text flows from one container to the next as expected. When a view is resized the following function is called:
protected function updateControllerDimensions():void
//AirConsole.Debug("TextFrameView updateControllerDimensions: " + this.width);
This sets the composition size on only the local containerController, but then calles updateAllControllers() on the shared textFlow. The expected result would be for only the local container to change size, but for the text to reflow across both containers to take account of the change. What actually happens is that the dimensions change on both the linked fields.
I've used the debugger to verify that the updateControllerDimensions() function is being called on only one of the views, and to confirm that there are two controllers attached to the flowComposer (one for each view, as expected).
I don't have time this week to break this out into a test application that I could post here but will try to do so next week. In the meantime, anything that might mean I don't have to do that would be welcome.
Many thanks, as always.
Jude Fisher / JcFx.Eu
I wrote a small app that shows the functionality, and it seems to be working for me. Can you try this and take a look and see what you're doing differently?
public class Bug extends Sprite
private var textFlow:TextFlow;
public function Bug()
const markup:String = '<TextFlow xmlns="http://ns.adobe.com/textLayout/2008" textAlign="start" fontFamily="Minion Pro" fontSize="16">I. Down the Rabbit-Hole<p textAlign="center" fontSize="24">Chapter I</p>' +
'<p textAlign="center" fontSize="24">Down the Rabbit-Hole</p>' +
'<p>Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice “without pictures or conversation?”</p>' +
'<p>So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.</p> ' +
textFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
var firstSprite:Sprite = new Sprite();
var firstController:ContainerController = new ContainerController(firstSprite, 200, 300);
var secondSprite:Sprite = new Sprite();
secondSprite.x = 250;
var secondController:ContainerController = new ContainerController(secondSprite, 200, 300);
private function traceController(controller:ContainerController):void
trace("Controller size", controller.compositionWidth, ",", controller.compositionHeight);
Thanks for your help with this. I've discovered the bug, which was in my own code. I'll describe it here in case anybody falls into the same trap:
My solution includes a columns implementation. When only one column was present, I was setting the containerFormat.columnCount to 1 and containerFormat.columnWidth to the width of the container, expecting this to have no effect, but to make reflecting these values easier in my toolbar. In fact, of course, this forces the entire composition to be fitted into the columnWidth (thus rendering a call to setCompositionSize() completely ineffective).
My patched code now sets columnCount and columnWidth to FormatValue.AUTO when there is only one column, and the linked fields resize as expected.
This could maybe be highlighted in the documentation for setCompositionSize(), as it is a bit odd to find that function completely overidden by the columnWidth value
Many thanks again,
Jude Fisher / JcFx.Eu