Creating Dynamic Scrolling Text Boxes with Flash CS3

Here’s a quick how to for creating dynamic scrolling text boxes in flash.  (This also works with Flash 8, Flash MX, and Flash MX 2004.)
Let’s say that you would like to have a text box in your flash movie and that you will be loading arbitrary amounts of text data into it.  You can set it up so that no matter how much text you add to the text instance you will have the scroll bar controls dynamically update to match.

This requires only two things, a text instance and an instance of the UIScrollBar component that ships with Flash.

  1. Create your text instance on the stage and size it appropriately.  Then drag an instance of the UIScrollBar to the stage.
  2. In the properties window set your text instance to "Dynamic" text, set it to "Multiline", and give it an instance name.  In this case, we’ll call it test_txt.
  3. Size the UIScrollBar instance vertically so that it matches the height of the text instance.
  4. Then next step is slightly different between CS3 and previous versions of flash.
    1. For CS3: Drag the UIScrollBar so that it is over either the left or right edge of the text instance.  When it snaps such that the edge of the text instance lines up with the middle of the UIScrollBar instance release the mouse.  It will move to the outside edge of the text instance and then be associated with that text instance
    2. For Flash 8, MX, MX 2004:  Drag the UIScrollBar so that it is inside the text instance.  Release it closest to either the left or right side of the text instance.  It will move to the outside of the text instance and then be associated appropriately.

Here is some sample code you can add to frame 1 of your sample movie to test it out.  Make sure that your text box isn’t so big that all of this text will be displayed without you having to scroll

test_txt.text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

stop();

Leave a Reply