Scrolling Text Horizontally
April 11, 2005
by James Newton
The movie above demonstrates a behavior that converts a single line text sprite into a horizontally scrolling sprite. Users can:
- Enter more text than can be shown in the visible area. As they do so, the text automatically scrolls to the left.
- Use the arrow keys and the page up and page down keys to move the insertion point within the member, and to scroll the text as necessary
- Cut and paste sections of text into the sprite.
Developers can:
- Set the text to appear in the sprite, using the
SetText()
method - Get the full text stored in the behavior, using the
GetText()
method - Give each behavior a distinctive ID, to identify the contents of the sprite in
SetText()
andGetText()
calls - Scroll the text from external scroll arrow sprites, using the
Scroll()
method - Set callback handlers to detect:
-
- when the user presses the RETURN, ENTER or TAB key to validate the text in the sprite
- when the user presses any other key
These handlers can be set in the Behavior Parameters Dialog. By default, the handlers are expected to be in other behaviors on the same sprite. The
SetCallback()
method allows you to define a script or instance to receive the callback events, and to set the callback handlers on the fly.
Tip
- In the Behavior Parameters dialog, set the ID of each Horizontal Scroll sprite to some meaningful value, then use
sendAllSprites()
with a property list as a parameter to set or get the text of a whole series of Horizontal Scroll behaviors in the same frame. The following example sets the text for behaviors with IDs of#name
and#email
:
tPropList = [:]
tPropList[#name] = "Enter your name here" tPropList[#email] = "your.name / at / domain.com" sendAllSprites(#setText, tPropList)
Limitations
- The text will not scroll automatically if the user drags a selection. Only the visible text will be selected. Text can be scrolled using the arrow keys.
- Control-A and menu Edit | Select All will only select the text from the first visible character to the end. As a workaround, a triple-click on the sprite will scroll to the start of the text and select the entire text.
Source files: scrollLeft.sit (Mac) | scrollLeft.zip (Windows)
James Newton started working with Director 5 in 1997. He wrote many of the
behaviors that ship with Director since version 7. James lives in Dunoon,
near Glasgow, Scotland. His company, OpenSpark Interactive, is responsible
for marketing PimZ OSControl Xtra. When not coding he can be found racing
his classic Flying Fifteen around the Holy Loch, making things with his four
children, or catching escaped hamsters.
Copyright 1997-2024, Director Online. Article content copyright by respective authors.