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!


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.setSize(16, dynafield._height);
scrollbar.move(dynafield._x + dynafield._width, dynafield._y);
} else {
dynafield.text = "Unable to load document.";

Alex said...

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

Andrea said...


This is the right way to fix it.