Skip to main content
Inspiring
March 19, 2009
Question

copy exact structure, data of textflow to its derieved class

  • March 19, 2009
  • 4 replies
  • 744 views
Hi All,

I am writing a class inherited the TextFlow ( public class myclass extends TextFlow {} )
Now in my new class, i want it able to read textFlow from a xml format file. So we could have a tempoary this way:
After file reading completion event, we could have:

tempFlow = TextFilter.importToFlow(e.target.data, TextFilter.TEXT_LAYOUT_FORMAT);

Then now i want my class owns this structure and data. (this = tempFlow)
of course, we can assign this = tempFlow.

Do you know how to do this exact copy?

Thank you for your answer,

Best,

-Hoang Long
This topic has been closed for replies.

4 replies

Adobe Employee
March 20, 2009
For the second replaceChildren was modified to no longer throw. That version of the swcs may not yet be public.

I assume deepCopy is working - otherwise cut/copy/paste would be broken. Can you post an example program of deepCopy failing?

texttileAuthor
Inspiring
March 20, 2009
hmm,,i don't see the content because the event complete reading of URLLoad is not thrown.
texttileAuthor
Inspiring
March 20, 2009
Richard,

the second while loop will throw this error message:
ArgumentError: newElement still owned by another FlowGroupElement
at flashx.textLayout.elements::FlowGroupElement/replaceChildren()
at flashx.textLayout.elements::FlowGroupElement/addChildAt()
at flashx.textLayout.elements::FlowGroupElement/addChild()

where as the first loop gives only one child of tempFlow and no content at all. (I tried the first loop and forgot to tell you in the previous message)

The content is truly one child (the divElement) but i also have some paragraph elements with text inside this element.

Any thoughts?

Regards,

-Hoang Long
Adobe Employee
March 19, 2009
Hi,

TextFlow not being marked final is a bug. Sorry about that. The other classes are marked final and this is an omission.

That said moving elements from one FlowElement to another can be accomplised fairly simply.

In order to an "exact" copy you'll want to copy the elements.
for (var idx:int = 0; idx < tempFlow.numChildren; idx++)
{
var elem:FlowElement = tempFlow.getChildAt(idx);
this.addChild(elem.deepCopy());
}

To just move the elements this will work.
while (tempFlow.numChildren)
this.addChild(tempFlow.getChildAt(0));

Note that's a recent change that addChild doesn't throw if the parameter already has a parent. The latest code removes the parameter from its existing parent.

Best Regards,
Richard