O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.13. Scrolling Text with the ScrollBar Component

Problem

You want to create a scrolling text field with a scrollbar.

Solution

Use the Flash UI Components ScrollBar component.

Discussion

Using the ScrollBar component, you can easily add both vertical and horizontal scrolling capabilities to a text field. If the text field is created during authoring, you can simply drag a scrollbar instance from the Components panel onto the text field itself. The ScrollBar component will automatically snap (if View Snap to Objects is enabled) to the side on which it is dropped (top, bottom, left, or right) and will automatically size itself to match the text field object. Additionally, the scrollbar instance will automatically set its scroll target to be the text field onto which it was dropped.

You can also add a scrollbar to a dynamically created text field, or add the scrollbar dynamically for other reasons (such as when a text field is resized or its contents change). To make the process fully dynamic, add the scrollbar using MovieClip.attachMovie( ) (see Recipe 7.19). To accomplish this, you must first make sure that the ScrollBar component is included in the movie’s Library by dragging an instance of it from the Components panel to the Stage. This action will automatically link the ScrollBar component for export with the identifier FScrollBarSymbol. With the symbol in the Library, you can attach the component using ActionScript, as follows:

_root.attachMovie("FScrollBarSymbol", "myScrollBar_sb", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required