Flash MX Scrollbar tutorial FAQ

I'm getting more and more email about my scrollbar tutorial on FlashKit, at least one a day. So far I have been answering them all. But I've been noticing lately that several of the questions repeat. So, for the sake of efficiency, here is a scrollbar tutorial FAQ.

FREQUENTLY ANSWERED QUESTIONS

  • How do I use the scrollbar with an external text file?
  • There are three steps to this.

    1. Create the external text file.

    For the purpose of this example, create a text file named external.txt in TextPad or whichever text editor you use. The file should contain the following:

    my_text=some text blah blah blah
    Just like that. No quotes and no semicolon.

    2. You need to create a LoadVars object to load the text into your movie.

    In the actions layer of the first frame of the root level of your movie, delete any code that is there and replace it with this:

    lv = new LoadVars();
    lv.onLoad = checkVars;
    lv.load("external.txt");
    stop();
    Now you need to define the checkVars function. In the first frame of the functions layer, add this function below the showText function that's already there:

    function checkVars(success) {
    if (success) {
    the_text = this.my_text;
    gotoAndStop(2);
    } else {
    trace("file didn't load");
    }
    }

    3. You need to give the Flash movie time to fully "digest" the external text.

    Time, in this case, means one frame. That's right. Give it one frame before you tell the movie to display the text. Right now, if you have done my tutorial, the root level of your movie only has one frame. Add a second frame to each layer. In the second frame of the actions layer, put this code:


    showText(the_text);
    stop();

    That's it! Also, if for some reason the scroll buttons don't work after doing all this, go to the main_mc movie clip and drag the functions code from the first frame to the second frame.

  • How come my scroll thumb scrolls past the arrow on the bottom?
  • This can happen if your scroll track and buttons are laid out differently from mine. You will need to adjust the following line:

    this.max_y = this.min_y + (scroll_track._height - up_arrow._height*2 - this._height/2) + 1;

    There is no one solution that will work for you, but one thing you can try is this:

    this.max_y = this.min_y + (scroll_track._height - up_arrow._height*2 - this._height) + 1;

  • Can I have the .fla from the tutorial?
  • Sure! Here is the regular scrollbar .fla, and here is the one that uses an external text file. Note that you are responsible for creating the external file yourself.

  • How do I include HTML in the scrollable text field?
  • Select your dynamic text field by clicking on it. Go to the Properties panel. Click the "<>" button to turn HTML on. Then click on "Character..." and select to embed font outlines for NO characters. Now all you have to do is set the .hmtlText property instead of the .text property of the text field. In my example, where you have the following in the functions frame of the root level


    main.w_field.text = message;


    replace "text" with "htmlText", like so:


    main.w_field.htmlText = message;


  • Do you know how to make a preloader?
  • Yes, I do. Here is an example .fla with a preloader in it. And this is what the .swf looks like.