Skip to main content
Inspiring
July 27, 2010
Answered

TLF Link Handling Questions

  • July 27, 2010
  • 1 reply
  • 759 views

Hello all,

I am working with tlf for my CMS and have easily implemented hyperinking with applyLink, however when I highlight the link again, how do I get the url that the selected text is linked to?

Also, if I have several editable textFlows on the stage, how can I maintain the highlighting?  When I click from the textflow to the edit controls my highlighting disapears. But when I set the textflows hightlighting to show always, if I click from editable text to editable text, I get multiple highlighted pieces of text.  This is confusing obviously.

Thanks for any input,

Jason

This topic has been closed for replies.
Correct answer robin_briggs

When the link is selected, you can get the link information by using the selection. The selected range is provided by the interactionManager, and you take the range and use it to find the link. To get the info on the first link in the selection, you could do something like this:

var pos:int = textFlow.interactionManager.absoluteStart;

var endPos:int = textFlow.interactionManager.absoluteEnd;

var leaf:FlowLeafElement = textFlow.findLeafAtPosition(pos);

while (pos < endPos)

{

     var link:LinkElement = leaf.getParentByType(LinkElement);

     if (link != null) // Found it!

     {

          return link.href;

     }

     pos = pos + leaf.textLength;

     leaf = leaf.getNextLeaf();

}

I haven't compiled this code or tested it, but something like this should get you what you need.

For your second question, about controlling the highlighting, you should define your own SelectionFormat. The SelectionFormat defines how the selection draws in each of three selection states: focused (when the TextFlow has keyFocus), unfocused (something else has keyFocus) and inactive (window is not active). TLF supplies your application with default SelectionFormats, which you can override by setting your own values, e.g.:

     textFlow.interactionManager.unfocusedSelectionFormat = new SelectionFormat(...);

Hope this helps,

- robin

1 reply

robin_briggsCorrect answer
Adobe Employee
July 28, 2010

When the link is selected, you can get the link information by using the selection. The selected range is provided by the interactionManager, and you take the range and use it to find the link. To get the info on the first link in the selection, you could do something like this:

var pos:int = textFlow.interactionManager.absoluteStart;

var endPos:int = textFlow.interactionManager.absoluteEnd;

var leaf:FlowLeafElement = textFlow.findLeafAtPosition(pos);

while (pos < endPos)

{

     var link:LinkElement = leaf.getParentByType(LinkElement);

     if (link != null) // Found it!

     {

          return link.href;

     }

     pos = pos + leaf.textLength;

     leaf = leaf.getNextLeaf();

}

I haven't compiled this code or tested it, but something like this should get you what you need.

For your second question, about controlling the highlighting, you should define your own SelectionFormat. The SelectionFormat defines how the selection draws in each of three selection states: focused (when the TextFlow has keyFocus), unfocused (something else has keyFocus) and inactive (window is not active). TLF supplies your application with default SelectionFormats, which you can override by setting your own values, e.g.:

     textFlow.interactionManager.unfocusedSelectionFormat = new SelectionFormat(...);

Hope this helps,

- robin

box86rowhAuthor
Inspiring
July 28, 2010

Hello Robin,

Thanks very much for the tips!

Here is the function I worked out from your code (which was pretty much spot on), txt is my textFlow object

            public function getCurrLink():String{
                var pos:int = txt.interactionManager.absoluteStart;
                var endPos:int = txt.interactionManager.absoluteEnd;
                var leaf:FlowLeafElement = txt.findLeaf(pos);
                while (pos < endPos)
                {
                    var link:LinkElement = leaf.getParentByType(LinkElement) as LinkElement;
                    if (link != null) // Found it!
                    {
                        return link.href;
                    }
                    pos = pos + leaf.textLength;
                    leaf = leaf.getNextLeaf();
                }
                return "";
            }