PDA

View Full Version : [AS3] UIScrollbar component doesn't scroll through all the text?


wendallsan
09-23-2008, 07:37 PM
Hi all, I have a small-ish text field with a decent amount of text in it which must be scrolled through to view it all. I've added a UIScrollBar component (using AS3), and it shows up fine and scrolls the text fine, but it doesn't scroll all the way down to the bottom of the text, just a little ways into it. If I click on the textfield, the scroll bar position indicator suddenly shrinks and then I can use the scroll bar clear to the end of the text. But if I don't click on the text field, I can't use the scroll bar to get to the end of the text. I've tried using the update() method of the scroll bar after filling the text field with it's content and attaching the UIScrollBar component to it. What am I missing here so that I can use the scroll bar to scroll all the way down through the text instead of just a little ways?

Here's the scrollbar prior to the click (you can see the big, long scrollbar position indicator, which tells the user that there's not much content to scroll down to). Scrolling down using the bar only scrolls a little ways, and you can't get to the end of the content using it.

http://www-app6.wa.gov/disit/sb1.jpg

And here it is after the click, you can see that the scrollbar position indicator is now much smaller, and it now scrolls down to the bottom of the content just fine.

http://www-app6.wa.gov/disit/sb2.jpg

Here's the code behind it:

var tf = new TextField(); // CREATE A TEXTFIELD
news_widget.addChild(tf); // ADD IT TO THE NEWS WIDGET
tf.htmlText = loader.data; // SET HTMLTEXT TO LOADER DATA
tf.wordWrap = true; // ALLOW WORD WRAP
tf.width = 115; tf.height = 160; // SET SIZE
tf.x = -(tf.width/2) - 10; tf.y = -(tf.height/2) + 20;// SET POSITION

var scrollbar:UIScrollBar = new UIScrollBar(); // CREATE NEW SCROLLBAR
news_widget.addChild(scrollbar); // ADD IT TO THE NEWS WIDGET
scrollbar.x = tf.width/2; scrollbar.y = -(tf.height/2) + 20; // POSITION
scrollbar.height = tf.height - 10; // SET SIZE
scrollbar.scrollTarget = tf; // ASSIGN SCROLL TO THE NEWS
scrollbar.update();

atomic
09-23-2008, 09:14 PM
Try switching text from static to dynamic...

wendallsan
09-23-2008, 11:06 PM
The default value is dynamic, so it already is . . .

wendallsan
09-29-2008, 05:47 PM
Apparently you must manually specify the max scroll range of the scroll bar. Assuming you've created a textfieild for the scrollbar to affect named content_tf, and the scrollbar is named scrollbar_tf, after the text is loaded into the textfield, this line of code will properly size the scrollbar to fit the text:

content_scrollbar.maxScrollPosition = content_tf.textHeight;

Go figure.