Skip to main content
Known Participant
August 24, 2009
Question

How can I catch a TextEvent.LINK in the new TLF?...

  • August 24, 2009
  • 3 replies
  • 2083 views

... or what should I use insetd of?

This topic has been closed for replies.

3 replies

Participant
August 27, 2009

Thanks for the replies! I was able to get linkelements linking this morning. There were two problems with my code:

  1. I was using an EditManager instead of a SelectionManager. Was able to uncover this problem when using the very handy http://labs.adobe.com/technologies/textlayout/demos/ site. Apparently links are only active in read mode...
  2. I was making a call to containerController.invalidateContents() after setting the interaction manager. This was basically wiping out the interaction manager, I think.

I really appreciate the responses, folks.

-Brad

Adobe Employee
August 27, 2009

With an EditManager hold the CTRL key down and mouse over the link.

ContainerController.invalidateContents marks all the text in the container as damaged.  Not clear to me just now why this is exposed..  You need to call textFlow.flowComposer.updateAllControllers after calling invalidateContents on the container though.

Richard

Known Participant
August 25, 2009

I found the solution...

I have to add an CLICK event listener... and than change that to a textEvent.LINK

public function set htmlText(htmlText:String):void
{
//... code
    textFlow = TextFilter.importToFlow(htmlText, TextFilter.TEXT_LAYOUT_FORMAT);
//... code
    textFlow.addEventListener(MouseEvent.CLICK, handleLinkClick, false,0,true);
//... code
}
private function handleLinkClick(event:FlowElementMouseEvent):void
{
    if (textFlow.interactionManager == null && event.flowElement is LinkElement)
    {
        event.preventDefault();

        dispatchEvent(new TextEvent(TextEvent.LINK,

                              LinkElement(event.flowElement).href));
    }
}

Participant
August 25, 2009

I have been dealing with the same problem, but unfortunately your solution didn't seem to work for me. When I include LinkElement <a> tags in my TextFlow, they are simply ignored and don't link anywhere. This is true even when I use the link.xml example included in the TLF distro (see attached). Am I supposed to handle the click event for link elements myself, and if so, how?

Adobe Employee
August 26, 2009

The default click handler in LinkElement simply does this.

                            var u:URLRequest = new URLRequest(encodeURI(href));
                            flash.net.navigateToURL(u, target);

Does that work for you?  Maybe something is blockig flash's ability to dispatch the event.  Note:  the code path is different if link.href begins with "event:".

Richard

Known Participant
August 24, 2009
Adobe Employee
August 25, 2009

I don't reccomend using the TLFTextField class.  It's simply for static text at this time.

Instead check out the TextContainerManager class.  It's similar but is more of a wrapper for TLF.  TCM also attempts to save memory by using a lightweight representation for a the content until it becomes editable.  Using that class there are several events associated with links.

http://livedocs.adobe.com/flex/gumbo/langref/flashx/textLayout/container/TextContainerManager.html

Hope that helps,

RIchard

Known Participant
August 25, 2009

thank you, but I am using the basic text layout framework class