Skip to main content
June 14, 2009
Question

How can I check if a selection has a link?

  • June 14, 2009
  • 1 reply
  • 563 views

private function setLinkToSelection (l : String) : void

{

     IEditManager(_textFlow.interactionManager).applyLink(l, "_blank");

}

...

private function onSelectionChange (e : SelectionEvent) : void

{

     // How can I check if there is an link?

}

I tried IEditManager(_textFlow.interactionManager).getCommonParagraphFormat() and getCommonCharacterFormat() but there ist no LinkProperty or LinkElement.

I will do the same as in the EditorExample from Adobe.

Select a text. Set a link to this text. Select this text again. Show the link on this text selection.

Any idea?

This topic has been closed for replies.

1 reply

Adobe Employee
June 14, 2009

Links aren't a property they are elements in the model.  You'll have to write some code for this.  Follows is some code that compiles - might need a bit of testing:

    public function selectionIsLink(textFlow:TextFlow):Boolean
    {
        if (!textFlow.interactionManager || !textFlow.interactionManager.hasSelection())
            return false;
        var start:int = textFlow.interactionManager.absoluteStart;
        var end:int = textFlow.interactionManager.absoluteEnd;
   
        var elem:FlowLeafElement = textFlow.findLeaf(start);
          while (start < end)
          {
            if (elem.getParentByType(elem,LinkElement))
                return true;
             start += elem.textLength;
             elem = elem.getNextLeaf();
          }
         
          return false;
    }
   
    public function getParentByType(elem:FlowElement,elementType:Class):FlowElement
    {
        var curElement:FlowElement = parent;
        while (curElement)
        {
            if (curElement is elementType)
                return curElement;
            curElement = curElement.parent;
        }
        return null;
    }

Regards,

Richard