ActionScript for Flash 5 dummies: Scrolling a text box.

So, you're a designer, and you have very little background in programming. You want to add interactivity to your Flash movies. You've heard of this thing called « ActionScript » , you thought it could do the job. You've checked out the Flash 5 manual, you tried to follow the examples, you tried again, then tried some more, then after a few days, you decided to give up before smashing your keyboard into your brand new 19 inch monitor. Well, this series of tutorials is intended for you.

Using a few classic examples of interactivity, I am going to show how to use ActionScript in a practical manner. I'll try to be as clear and concise as possible. Hopefully, by the end of the series, you'll be able to add interactivity to your Flash movies, with a minimal amount of collateral damage to your surrounding hardware or small pets.

The Movie

If there's a question that gets asked the most at the Flash 5 board here at Flashkit, then it's probably « How do I scroll a text box » (although « Why can't this stupid piece of **** work? » is not far behind).

Scrolling a text box is not as easy as it seems. It involves quite a bit of ActionScript, which is a bit *intimidating* to the beginner. Well, fear not, using my technique, by the end of the day, you'll be able to scroll a text box just like this:

Setting things up

Okay, first of all you'll need to make two buttons: up and down. They can be of any shape you want. You may want to give the buttons a big hit area so that the user can be slightly off the button and still be able to scroll.

Next you'll need to make a textbox. Just click on the text tool and let your inspiration carry you. You can let the text overflow, we'll fix this later.

Now select the text and go into the « Text Options » panel. Set the options as in this screenshot:

If you can't seem to find the panel, it's in Window > Panels > Text options. Here's what each of the options do:

We choose dynamic text, since it is the only kind of textbox where you can alter the scroll property in actionscript. There's a nice side effect to using dynamic text: unless you choose to embed your fonts, the text will not be anti-aliased, so it will look good even at small sizes.

Choosing Multiline will allow the text to spread across multiple lines.

We set the variable name to "daTextBox" here. We'll use this name later to refer to the textbox in ActionScript.

By choosing HTML, we can apply basic formatting on the text ( color, size, bold, italics, and hyperlinks )

Word wrap works in conjunction with multiline to allow the text to wrap.

There is something peculiar in the way Flash handles text boxes and scrolling: you can't scroll a text box unless you fill its contents using ActionScript. In order to do this, you can load external text files into Flash, but that's much beyond the scope of this tutorial. Right now, we're just going to place the contents of the text box directly in Actionscript (a technique called «hard-coding» ).

There's an easy way to transfer the text ( or rather, the underlying HTML ) from the text box to ActionScript. When you test your movie (Ctrl+enter), you can see a list of the variables in the movie by going to the Debug menu and choosing « List Variables ». You should see something similar to this:

As you can see, the HTML content of the text box is accessible (it's on the second-to-last line, in this case). Select all of the HTML, copy it, and then paste it into Notepad or a similar program. Save this for later use.

Once this is done, you can go back to your Flash movie, and safely delete the contents of the text box. You should reduce its height as well, otherwise there won't be a need for scrolling.

Finally, place your text box and your two buttons on the main timeline, select everything, and press F8 to convert to a movie clip. Name it «containerMC» . Our setup is now done.