Skip to main content
Participant
August 27, 2010
Question

Can you link 2 text containers in one flow composer?

  • August 27, 2010
  • 1 reply
  • 580 views

Here is what I am trying to do but all I see is the text in the second text container. Has anyone got a solution for this?

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init()" horizontalAlign="left" backgroundColor="#ffffff">

<mx:Script>

<![CDATA[

import flashx.textLayout.conversion.TextConverter;

import flashx.textLayout.container.ContainerController;

import flashx.textLayout.compose.StandardFlowComposer;

import flashx.textLayout.elements.TextFlow;

private var _textFlow:TextFlow

private var _defController:ContainerController;

private var _textContainer:Sprite;

private static const textInput1:XML = <TextFlow color="0x0" fontFamily="Times New Roman" fontSize="12" fontStyle="normal" fontWeight="normal" lineHeight="15" paragraphStartIndent="10" textAlign="left" textDecoration="none" textIndent="0" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008">

        <p><span>TEXT 1</span></p>

        <p><span>TEXT 1</span></p>

        <p><span>TEXT 1</span></p>

        <p><span>TEXT 1</span></p>

      </TextFlow>;

      private static const textInput2:XML = <TextFlow color="0x0" fontFamily="Times New Roman" fontSize="12" fontStyle="normal" fontWeight="normal" lineHeight="15" paragraphStartIndent="10" textAlign="left" textDecoration="none" textIndent="0" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008">

        <p><span>TEXT 2</span></p>

        <p><span>TEXT 2</span></p>

        <p><span>TEXT 2</span></p>

        <p><span>TEXT 2</span></p>

      </TextFlow>;

private function init():void {

_textFlow = new TextFlow();

_textFlow.flowComposer = new StandardFlowComposer();

_textFlow = TextConverter.importToFlow(textInput1, TextConverter.TEXT_LAYOUT_FORMAT);

var textContainer1:Sprite = new Sprite();

textContainer1.x = 100;

canvas.rawChildren.addChild(textContainer1);

var cc1:ContainerController = new ContainerController(textContainer1, 600, 400);

_textFlow.flowComposer.addController(cc1);

_textFlow = TextConverter.importToFlow(textInput2, TextConverter.TEXT_LAYOUT_FORMAT);

var textContainer2:Sprite = new Sprite();

textContainer2.x = 500;

canvas.rawChildren.addChild(textContainer2);

var cc2:ContainerController = new ContainerController(textContainer2, 600, 400);

_textFlow.flowComposer.addController(cc2);

_textFlow.flowComposer.updateAllControllers();

}

]]>

</mx:Script>

<mx:Canvas id="canvas" width="100%" height="100%"/>

</mx:Application>

This topic has been closed for replies.

1 reply

August 27, 2010

When you call TextConverter.importToFlow an entirely new TextFlow is created, without the text from before and without the cc1 controller you set up before. That's why you're only seeing what gets added to that new TextFlow after the second call to importToFlow.

Instead of this line:

_textFlow = TextConverter.importToFlow(textInput2, TextConverter.TEXT_LAYOUT_FORMAT);

try making a temporary TextFlow, then copying its children into your initial TextFlow. You could also convert the temporary TextFlow into a TextScrap object and paste it wherever you need in your initial TextFlow, if you want to set up an EditManager.

var tempTextFlow:TextFlow = TextConverter.importToFlow(textInput2, TextConverter.TEXT_LAYOUT_FORMAT); while (tempTextFlow.numChildren > 0) {   _textFlow.addChild(tempTextFlow.getChildAt(0)); } tempTextFlow = null;

spapaj45Author
Participant
August 30, 2010

Thank you very much for this Alan, I understand what you explained.

My problem is actually a bit more complex I am working on an emulation

of a word processor where you can insert images, tables and graphs and

I was looking at the TLF to have more control over the formatting of

the text and paragraphs, but we have issues with inserting

UIComponents inside the TextFlow object. We also need to be able to

resize inserted image which proves to be quite difficult since the

image is seen as an inline image part of the textFlow and not a

UIComponent.

So what we are trying to do is to split the text into different

containers but inside one textFlow mainly for text Editing and

Selection, to be able to get to the images or tables in between.

If you have any suggestions, please let know.

Thanks

August 30, 2010

Another forum user figured out how to get Flex objects into TLF inlines. He described it here:

http://forums.adobe.com/message/2904297#2904297