Skip to main content
Jun 19, 2009 9:54 PM UTC
Answered

How to copy a textflow?

Dear Sirs,


I need make a copy of textflow, but I'm having difficulties. I try to use the deepCopy, but it also copies the header <textflow /> , and when I insert in another textFlow, it's duplicate:

var el1: FlowElement = textflow.deepCopy();

textFlow2.replaceChildren(0, textflow.numChildren, el1);

Result:

<TextFlow whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008"><TextFlow whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008">Teste</TextFlow></TextFlow>

Is there some way to go about this?

This topic is closed to new replies. Start a new post to keep the conversation going.
rdermerCorrect answer
Inspiring
Jun 22, 2009 3:58 PM UTC

I'm not sure what getTextFlow() and getTextFlow2() return.

My original example wasn't tested - sorry about that.  The below works.  Iin older builds addChild does not automatically remove a child from its parent.  More recent builds do.  For that you will need to use the code in green.

var textFlow:TextFlow = TextFilter.importToFlow(markup, TextFilter.TEXT_LAYOUT_FORMAT);

var copiedTextFlow:TextFlow = textFlow.deepCopy() as TextFlow;

var someOtherTextFlow:TextFlow = new TextFlow();

someOtherTextFlow.replaceChildren(0, someOtherTextFlow.numChildren);

while (copiedTextFlow.numChildren)

{

// in order builds this is a little more complicated (psuedo code here you will have to debug it)

// var child = copiedTextFlow.getChildAtIndex(0);

// copiedTextFlow.removeChild(child);

// someOtherTextFlow.addChild(child);

someOtherTextFlow.addChild(copiedTextFlow.getChildAtIndex(0));

}

Regards,

Richard

5 replies

Jun 22, 2009 1:58 PM UTC
Still can not, any idea?

Regards,
Marcos Passos
Translate
rdermerCorrect answer
Inspiring
Jun 22, 2009 3:58 PM UTC

I'm not sure what getTextFlow() and getTextFlow2() return.

My original example wasn't tested - sorry about that.  The below works.  Iin older builds addChild does not automatically remove a child from its parent.  More recent builds do.  For that you will need to use the code in green.

var textFlow:TextFlow = TextFilter.importToFlow(markup, TextFilter.TEXT_LAYOUT_FORMAT);

var copiedTextFlow:TextFlow = textFlow.deepCopy() as TextFlow;

var someOtherTextFlow:TextFlow = new TextFlow();

someOtherTextFlow.replaceChildren(0, someOtherTextFlow.numChildren);

while (copiedTextFlow.numChildren)

{

// in order builds this is a little more complicated (psuedo code here you will have to debug it)

// var child = copiedTextFlow.getChildAtIndex(0);

// copiedTextFlow.removeChild(child);

// someOtherTextFlow.addChild(child);

someOtherTextFlow.addChild(copiedTextFlow.getChildAtIndex(0));

}

Regards,

Richard

Translate
Jun 24, 2009 4:13 PM UTC
Worked perfectly!

Thanks!
Translate
Inspiring
Jun 19, 2009 10:41 PM UTC

Hi,

el1 is already a TextFlow.

So you could do one of two things.

1) Just use it.

textFlow2 = el1 as TextFlow

2) move the children one at a time into textFlow2

while (FlowGroupElement(el1))

     textFlow2.addChild(FlowGroupElement(el1).getChildAt(0));

BTW It's a bug that you were able to nest TextFlows.  I'll get that logged.

Regards,

Richard

Translate
Jun 20, 2009 1:51 PM UTC

Thanks for answer, but unfortunately didn't work.

I try:

var child: FlowElement = getTextFlow2().deepCopy();

getTextFlow().replaceChildren(0, getTextFlow().numChildren);
               
while (FlowGroupElement(child))

      getTextFlow().addChild(FlowGroupElement(child).getChildAtIndex(0));

Results:
ArgumentError: newElement not of a type that this can be parent of
    at flashx.textLayout.elements::FlowGroupElement/replaceChildren()
    at flashx.textLayout.elements::FlowGroupElement/addChild()
    at com.bookess.controls::Header/insertContent()
    at <anonymous>()
    at Vector.<*>$/_forEach()
    at Vector$object/http://adobe.com/AS3/2006/builtin::forEach()
    at com.bookess.controls::HeaderController/updateHeaderContent()
    at com.bookess.controls::HeaderController/addHeader()
    at com.bookess.controls::EditorBase/insertHeader()
    at <anonymous>()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()
    at <anonymous>()

Translate