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", ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access