Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

how to remove a linkElement?

Explorer ,
Feb 02, 2012 Feb 02, 2012

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

TOPICS
Text layout framework
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Feb 02, 2012 Feb 02, 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);

Translate
Adobe Employee ,
Feb 02, 2012 Feb 02, 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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2012 Feb 02, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 02, 2012 Feb 02, 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2012 Feb 02, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines