TextArea auto scroll update

by DeanLogic

There was a question on the Flex Forum about how to auto-scroll a TextArea. You can set the VerticalScrollPolicy to auto or you can add a little code to valueCommit to move the vertical scroller. Since I lost where I created the example of adding the code to the valueCommit, I decide to remake the example to show the difference. Both text areas are updated every 10 seconds with a random generated sentence, based off of quotes from Mark Twain.

The left TextArea box uses the VerticalScrollPolicy set to “auto”

<s:TextArea id="tmpTxtArea1" width="98%" height="98%" verticalScrollPolicy="auto" />

The right TextArea box uses the valueCommit code to move the verticalScrollBar

<s:TextArea id="tmpTxtArea2" width="98%" height="98%" 
   valueCommit="tmpTxtArea2.scroller.verticalScrollBar.value = tmpTxtArea2.scroller.verticalScrollBar.maximum"  />

View Source

While the right box doesn't move the TextArea scroll bar 100%, it does move it.

The current issues I need to update with this example is a better random sentence generator and fix the regular expression that is supposed to remove the commas and periods before creating the word array. That's probably some sort of project I can do later, so the sentences created are a little bit off, since I don't remember how I did it in the previous example and the site I got the code idea from is no longer available.

About DeanLogic
Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.

Leave a Reply