Do-It-Yourself Scrollbar: Vs. 1.1
by Alan Burkhart
|This is a pretty good scrollbar for scrolling text or other objects within your Flash movie. It doesn’t require too much coding and it uses simple|
ActionScript commands that most people learn soon after getting Flash Designer. It resizes itself automatically for the number of lines in your HTML text field. Once it’s complete, you can insert it into any SWF with an HTML text field or edit field, add two lines of code to your project, and have a working scrollbar. You can click an arrow to move the text up or down one line, click and drag the bar, or click in the track to make the text “jump” several lines.
|How to insert a scrollbar|
Click Frame > ActionScript and paste the following code into the dialog:
If the name of your HTMLText field is not “HTMLText1” then change the first line of this code accordingly. The name of your text field should appear inside the “()”. Note that you should not put the name in quotes.
Press F9 to preview Flash
Create your own scrollbar
Now let’s build the scrollbar…
|Making it work…|
Click Frame > ActionScript and paste the following code into the ActionScript dialog:
//Set vert coords for track and bartrky=track._y; //Y coord for trackbary=trky+3; //Y coord for bar (with next line)bar._y=bary;
//This object gets text field size from parent SWF
//LL is the “Lower Limit” variable. This defines the bottom
//Defines the height of the track by adding the bar height
//Sets the Y coord for the down arrow at the
//when the track is clicked, this moves the bar to
//scrolls text up one line to make the next lower
//enables user to drag the bar up and down
//if z equals 1, text will scroll and any other scripting is enabled
//disable drag when mouse button is released over the bar
//disable drag when mouse is released outside the bar
Time to test the scrollbar…
In scrollbar_demo, click “Insert” > “SWF Clip”. Select “scrollbar_01” and click “Open”. This places the scrollbar in your larger file. Place the scrollbar at the extreme top/right.
Hit Flash Designer’s Preview button and see how it looks. If everything is in place, drag “bar” up and down to be sure the text scrolls as you do so. If that works okay, try clicking the track to make the text jump up and down. The bar should jump to the spot you clicked on the track. Lastly, click the up and down arrows. These move the text one line with each click. At present the arrows don’t scroll continuously. I’m working on that and will (hopefully) release an updated version sometime soon. I’m open to suggestions on this issue.
Stuff To Remember: