Skip to main content
Participating Frequently
February 2, 2010
Answered

How to get the active Paragraph?

  • February 2, 2010
  • 1 reply
  • 500 views

I have following TLF XML:

private var text:XML =

<flow:TextFlow fontSize="20" paddingRight="50" paddingBottom="50" paddingTop="50" paddingLeft="50" whiteSpaceCollapse="preserve" xmlns:flow="http://ns.adobe.com/textLayout/2008">
        <flow:p>
                 <flow:span>Hallo liebers Programmili... du tust schon langsam meinem koepchen weh</flow:span>
        </flow:p>

</flow:TextFlow>;

I try to get the Paragraph for a selection inside the text using following Methodes:

var index:int = tf.interactionManager.anchorPosition; // i get 29 here
var child:FlowElement = tf.getChildAtIndex(index); // undefined - it should be the flowElement containing the text... <flow:span></flow:span>
var para:ParagraphElement = test.getParagraph();//undefined - it should be the paragraph

I really started to enjoy the new framework... but now i am getting really mad

Can anybody imagine what i am doing wrong? The undefined itself makes me suspicious... shouldn't it be null?

Help would be much appriciated!

This topic has been closed for replies.
Correct answer rdermer

You are confusing index and position.

What you want is:

var position:int = tf.interactionManager.anchorPosition;     // this is a position not an index

var leaf:FlowLeafElement = tf.findLeaf(position);     // maps a position to a leaf

var para:ParagraphElement = leaf.getParagraph();     // find the leaf element's owning paragraph

Also consider whether you want the anchorPosition or the activePosition.  In a point selection they are the same.  In a block selection the anchor is where the block began and the active is the end being modified by the UI (mouse dragging and keys).

Hope that helps,

RIchard

1 reply

rdermerCorrect answer
Adobe Employee
February 2, 2010

You are confusing index and position.

What you want is:

var position:int = tf.interactionManager.anchorPosition;     // this is a position not an index

var leaf:FlowLeafElement = tf.findLeaf(position);     // maps a position to a leaf

var para:ParagraphElement = leaf.getParagraph();     // find the leaf element's owning paragraph

Also consider whether you want the anchorPosition or the activePosition.  In a point selection they are the same.  In a block selection the anchor is where the block began and the active is the end being modified by the UI (mouse dragging and keys).

Hope that helps,

RIchard

NewFloAuthor
Participating Frequently
February 3, 2010

You are right!

Thank you very much RIchard!