Skip to main content
Inspiring
February 2, 2012
Answered

how to remove a linkElement?

  • February 2, 2012
  • 2 replies
  • 1306 views

Hi

i've inserted a linkElement with a code such as this:

  var edit:IEditManager = textFlow.interactionManager as IEditManager;

  edit.selectRange(from,to);

  edit.applyLink(url,'_blank');

  textFlow.flowComposer.updateAllControllers();

and up to here all ok!

Now I must remove this linkElement, but I have not found functions to do this.

any help is welcome.

thank in advance

JeanPaul

This topic has been closed for replies.
Correct answer Jin-Huang

For 2), I think it should be a loop in case that the structure is complex sometimes. 'Ancestor' is not just 'parent'.

3)

var link:LinkElement;

var children:Array = link.mxmlChildren.deepCopy();

var parentOfLink:FlowGroupElement = link.parent as FlowGroupElement;

var indexOfLink:int = parentOfLink.getChildIndex(link);

parentOfLink.replaceChildren(indexOfLink, indexOfLink + 1, children);

2 replies

Inspiring
February 3, 2012

No problem for the step 2, before performing    var lnk:LinkElement = span.parent as LinkElement;    I'm sure to be on the text connected to the link.

link.mxmlChildren.deepCopy();     give Error #1006: deepCopy is not a function.

I must replace with link.mxmlChildren.concat();     and then all work correctly

thank for all

Adobe Employee
February 2, 2012

Yes, there is no one-line API to convert link back to plain text.

I believe there are many ways, one of which is as follows.

1)get the leaf element according to 'from' of selection

2)get the link element based on the leaf element returned in step 1 (detect leaf's ancestors, if it's a link, it must be the target link)

3)replace link element with all children elements of the link (the array of all children elements can be the third paramter of function link.parent.replaceChildren())

4)textflow.flowComposer.updateAllControllers()

Inspiring
February 2, 2012

Hi Jin-Huang

after the applyLink statament, the textFlow markup is similar to this:

    <p><span>text before link</span><a href="http://www.link.com" target="_blank"><span>text of link</span></a><span>text after link</span></p>

a way to remove the link can be to act on the markup and than import it in textFlow, but I prefer your solution!

ok for first step, it point to span element that contains text of link, I think that to find the link can be used:

         var lnk:LinkElement = span.parent as LinkElement;

but for the third step i don't know the statement.

can make me an example?

Jin-HuangCorrect answer
Adobe Employee
February 3, 2012

For 2), I think it should be a loop in case that the structure is complex sometimes. 'Ancestor' is not just 'parent'.

3)

var link:LinkElement;

var children:Array = link.mxmlChildren.deepCopy();

var parentOfLink:FlowGroupElement = link.parent as FlowGroupElement;

var indexOfLink:int = parentOfLink.getChildIndex(link);

parentOfLink.replaceChildren(indexOfLink, indexOfLink + 1, children);