You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Scott Matheson <sm...@intralinks.com> on 2014/04/07 22:29:04 UTC

TextFlow lastParagraph

Hi
   I am trying to dynamical add spanElement to the last paragraph of a text flow, I just can not see how this works  i know this is work but..

ta  is the textArea that the text flow is to be added too.


var paragraph1:ParagraphElement = new ParagraphElement();

var span1:SpanElement = new SpanElement();

var linkWrapper:LinkElement = new LinkElement();

var leaf:SpanElement = new SpanElement();              // caculate the last paragrah in the text flow

leaf = SpanElement(ta.textFlow.get.getLastLeaf());         // i was hopping this would get a link tit he textArea

var p:ParagraphElement = leaf.getParagraph();

span1.text = "some text";

linkWrapper.addChild(span1)

p.addChild(linkWrapper);


________________________________

Disclaimer: This electronic mail and any attachments are confidential and may be privileged. If you are not the intended recipient, please notify the sender immediately by replying to this email, and destroy all copies of this email and any attachments. Thank you.

Re: TextFlow lastParagraph

Posted by Joseph Balderson <ne...@joeflash.ca>.
I struggled with this for a while as well. If you're creating a LinkElement,
it's best to use interactionManager.applyLink.  Here's a snippet of what I used
to dynamically create a link.


// linkURL & linkText defined from TextInputs elsewhere
// editor = TextArea
interactionManager = editor.textFlow.interactionManager as EditManager;

...

// here we use absoluteStart & absoluteEnd
// instead of anchorPosition & activePosition,
// b/c if the user selected 'backwards' these will not be in the right order
var _selStart:int = interactionManager.absoluteStart;
var _selFinish:int = interactionManager.absoluteEnd;
var _selState:SelectionState = new SelectionState(editor.textFlow, _selStart,
_selFinish);

// create link element
var linkElement:LinkElement = interactionManager.applyLink(linkURL, "_blank",
true, _selState);
var linkElementSpan:SpanElement = linkElement.getFirstLeaf() as SpanElement;
linkElementSpan.text = linkText;

// position cursor after the (possibly modified) link text
interactionManager.selectRange(_selFinish,_selFinish);


Keep in mind this is a simplistic example, and will only work if you're not
selecting across spans with other formatting, or across list elements, etc -- in
which case you'll have to "cut out" the selected text, then "insert" it back in
to remove all the formatting and containers, then create the LinkElement around
that text. But this should get you started. I recommend looking at
interactionManager.cutTextScrap() and interactionManager.insertText().

_______________________________________________________________________

Joseph Balderson, Flex & Flash Platform Developer :: http://joeflash.ca
Author, Professional Flex 3 :: http://tinyurl.com/proflex3book

Scott Matheson wrote:
> Hi
>    I am trying to dynamical add spanElement to the last paragraph of a text flow, I just can not see how this works  i know this is work but..
> 
> ta  is the textArea that the text flow is to be added too.
> 
> 
> var paragraph1:ParagraphElement = new ParagraphElement();
> 
> var span1:SpanElement = new SpanElement();
> 
> var linkWrapper:LinkElement = new LinkElement();
> 
> var leaf:SpanElement = new SpanElement();              // caculate the last paragrah in the text flow
> 
> leaf = SpanElement(ta.textFlow.get.getLastLeaf());         // i was hopping this would get a link tit he textArea
> 
> var p:ParagraphElement = leaf.getParagraph();
> 
> span1.text = "some text";
> 
> linkWrapper.addChild(span1)
> 
> p.addChild(linkWrapper);
> 
> 
> ________________________________
> 
> Disclaimer: This electronic mail and any attachments are confidential and may be privileged. If you are not the intended recipient, please notify the sender immediately by replying to this email, and destroy all copies of this email and any attachments. Thank you.
>