Skip to main content
June 19, 2009
Answered

How to copy a textflow?

  • June 19, 2009
  • 2 replies
  • 1391 views

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 has been closed for replies.
Correct answer rdermer

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

2 replies

June 22, 2009
Still can not, any idea?

Regards,
Marcos Passos
rdermerCorrect answer
Adobe Employee
June 22, 2009

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

June 24, 2009
Worked perfectly!

Thanks!
Adobe Employee
June 19, 2009

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

June 20, 2009

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>()