Skip to main content
Known Participant
September 3, 2009
Answered

Scroll to TextLine

  • September 3, 2009
  • 1 reply
  • 1822 views

Hi there,

I have this list of pararaphs, that in my application stand for the start of a new page, I put these in a little combobox so the user can jump between pages in my app by selecting an item. (The whole TextFlow is in one container). By selecting an item, the specified paragraph then scrolls to the top of the container.

I thought this mechanism was easy enough to implement, like this:

var startPos:int = paragraphElement.getAbsoluteStart();

var tfl:TextFlowLine = textFlow.flowComposer.findLineAtPosition(position);
containerController.verticalScrollPosition = tfl.y;

Now, this works like a charm for the first couple of paragraphs, but later on the textflowline has a y property of 0.

I understand now that this is, of course, because these lines haven't been drawn yet.

So, obviously I'm using the wrong technique for this, therefore my question:

Is there a different way of scrolling an arbitrary paragraph in your textflow to the top of your container?

Any help will be greatly appreciated, thanks in advance!

cheers,

Roland

This topic has been closed for replies.
Correct answer rdermer

Use composeToPosition instead of scrollToPosition and then use your logic to scroll to the TextLine.  There is another API getScrollDelta on ContainerController that may be useful.

Richard

1 reply

Adobe Employee
September 4, 2009

Use containerController.scrollToRange(startPos,startPos);

The text isn't composed yet because TLF stops composing after the end of the visible text.  The TextFlowLine is a placeholder with all the overflow text in it and no computed location.

Richard

mech-headAuthor
Known Participant
September 4, 2009

Hey Richard,

thanks for taking the time to reply.

I had already tried scrollToRange(), but it doesn't do precisely what I need. It scrolls the necessary text into view. Whereas I need to have the first line of the paragraph to be exactly at the top of my container.

Right now I did a bit of an ugly hack, but it works for now, I first call scrollToRange() (then I'm certain the textflow will have been composed) and then I call my other code to position it to the top of the container.

It ain't pretty, but for now it works   I've looked at the source for scrollToRange(), which is about a page of adding and substracting all kinds of positions, so when I find a bit more time I'll try to analyze that and come up with a 'clean' way of scrolling to the top.

cheers,

Roland

rdermerCorrect answer
Adobe Employee
September 4, 2009

Use composeToPosition instead of scrollToPosition and then use your logic to scroll to the TextLine.  There is another API getScrollDelta on ContainerController that may be useful.

Richard