I'm looking for the best method to auto-scroll my Spark TextArea to the bottom when I add text in it.
I'm adding text using textFlow.addChild() and I listen the CompositionCompleteEvent.COMPOSITION_COMPLETE event on the textFlow component in order to set the vertical scrollbar value to its maximum.
But sometimes, it doesn't work very well... Maybe I'm not using the proper event, on the appropriate object... That's why I'm asking for your help ^^
Thanks you in advance !
It really is lonely when nobody answers your questions. lol
Unfortunately, I have no answers for you because I'm a newbie. But let me ask you something. Say I have a box with news items (text) and I want it to scroll continuously, would you know how to accomplish that?
I tried TextOperationEvent ton both TextArea and TextArea.textFlow
instances, but this doesn't help... This event seems to not being fired
Le 25/03/2011 21:22, Codeflayer a écrit :
I'm just shooting in the dark here but maybe you could listen for the TextOperationEvent and force the text area to scroll to the bottom?
Inspired from a similar solution for a List component, I do :
public final function scrollToBottom():void
verticalScrollBar.value = verticalScrollBar.maximum;
Called twice :
- On CompositionCompleteEvent.COMPOSITION_COMPLETE of the textFlow component
- And at the end of the function where I do textFlow.addChild(...)
It works relatively well
Here's the basic code. It does have limitations.
<s:TextArea id="fooText" width="200" height="200" valueCommit="fooText.scroller.verticalScrollBar.value = fooText.scroller.verticalScrollBar.maximum" />
You will notice in my updated example, setting the verticalScrollPolicy to "auto", does not move the TextArea up.
Message was edited by: DeanLoganBH - added link to updated blog post and view source