programmatically add hyperlink to TextFlow
Hello,
currently I add hyperlinks to a TextFlow the following way:
public function setHyperLink( linkInput:String ):void { if (editor.selectionActivePosition != editor.selectionAnchorPosition) { var content:String = TextConverter.export(editor.textFlow , TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE).toString(); var selection:String = editor.text.substring( editor.selectionAnchorPosition,editor.selectionActivePosition );
var text:String = TextConverter.export( editor.textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE ).toString(); var arr:Array = text.split( selection ); var output:String = arr[0]+"</span>" +
"<a href='"+linkInput+"' target='_blank'>" + "<span>"+selection+"</span>"+ "</a>" + "<span>"+arr[1]; editor.textFlow = TextConverter.importToFlow( output, TextConverter.TEXT_LAYOUT_FORMAT ); }
}
This works fine until the selection:String is "2008", which leads to a incorect split since tghe markup String contans 2008:
"<TextFlow whiteSpaceCollapse="preserve" version="2.0.0" xmlns="http://ns.adobe.com/textLayout/2008">"
Anyone see another way to get the textflow before and after a certain position ?
Probably with "editor.textFlow.shallowCopy" ? But than I have FlowElements.
But how to join those FlowElements and my hyperlink together as textflow ?
beforeLinkFlowElement + link + afterLinkFlowElement ?
...
How do you add links in this demo:
http://labs.adobe.com/technologies/textlayout/demos/
?
[EDIT:]
ok found:
http://tourdeflex.adobe.com/flex4.0/TLF/srcview/index.html
I am going to study this now
[EDIT:]
Ok i found which is working, but how to set the default link color/look? There is no default after applying this function?
private function changeLink(urlText:String, targetText:String, extendToOverlappingLinks:Boolean):void
{
if (activeFlow && activeFlow.interactionManager is IEditManager)
{
IEditManager(activeFlow.interactionManager).
IEditManager(activeFlow.interactionManager).applyLink(urlText, targetText, extendToOverlappingLinks);
activeFlow.interactionManager.setFocus();
}
}
Those Interfaces make it quite hard to understand
