2007-05-14

Using the UIScrollBar component of Flash

In a recent project I tried to use the UIScrollBar component of Flash 8. There are already a lot of tutorials on the web:
  1. Creating a Flash Textbox Input
  2. Creating a Text Scroller
If you do that step by step, it works. BUT, if you create a new text box with the type of dynamic text, use LoadVars to load a text file on the fly and add a UIScrollBar component to it, then publish it, you will see a blank vertical bar on the right of the text box. So what's wrong?

There are also people writing comments on the Adobe livedocs. Such things cost me at least one hour to find what happens.

The key to the solution is: you must enter something long enough in the text box before loading anything into it! I guess the UIScrollBar component just caculates the behavior before it's published. The only size it knows is your text size in the design phase.

So, don't forget to paste some dummy text in your text box and give it an instance name before you use the UIScrollBar component!

3 comments:

Lawrie said...

The problem with this method is you already have to know the approximate length of your content before it's loaded.

A much more certain method: you can attach the UIScrollBar component on the success of loading your external document:

function loadDocument(arg) {
loadfile = new LoadVars();
loadfile.load(path + doc);
loadfile.onLoad = function(success) {
if (success) {
dynafield.htmlText = this.filedata;
scrollbar.setScrollTarget(dynafield);
scrollbar.setSize(16, dynafield._height);
scrollbar.move(dynafield._x + dynafield._width, dynafield._y);
} else {
dynafield.text = "Unable to load document.";
}
};
}
loadDocument("loremipsum.txt");

Alexwils said...

An easier way is just to have the load variables code on the frame before the text field - it works then!

Anonymous said...

http://www.tyronedavisjr.com/index.php/2007/12/03/flash-cs3-uiscrollbar-scroll-arrows-not-displaying-on-dynamic-text/comment-page-1/

This is the right way to fix it.