ActionScript 2.0 Components Language Reference |
|
|
|
| UIScrollBar Component > UIScrollBar.scrollPosition | |||
Flash Player 6 (6.0.79.0).
Flash MX 2004.
scrollBarInstance.scrollPosition
Property; gets or sets the current scroll position of the scroll box (thumb) when a new scrollPosition value is set. The value of scrollPosition depends on whether the UIScrollBar instance is being used for vertical or horizontal scrolling.
Set the scrolling of the scroll bar target instance separately, using the following syntax:
my_scrollbar._targetInstanceName.scroll = 20;
If the UIScrollBar instance is being used for vertical scrolling (the most common use), the value of scrollPosition is an integer with a range that begins with 0 and ends with a number that is equal to the total number of lines in the text field divided by the number of lines that can be displayed in the text field simultaneously. If scrollPosition is set to a number greater than this range, the text field simply scrolls to the end of the text.
To set the scroll box (thumb) to the first line, set scrollPosition to 0.
To set the scroll box (thumb) to the end, set scrollPosition to the number of lines of text in the text field minus 1. You can determine the number of lines by retrieving the value of the maxscroll property of the text field.
If the UIScrollBar instance is being used for horizontal scrolling, the value of scrollPosition is an integer value ranging from 0 to the width of the text field, in pixels. You can determine the width of the text field in pixels by getting the value of the maxhscroll property of the text field.
The default value of scrollPosition is 0.
The following example sets the text to position 20:
/**
Requires:
- UIScrollBar and Button components in library
*/
this.createTextField("my_txt", 10, 10, 20, 200, 100);
this.createClassObject(mx.controls.UIScrollBar, "my_sb", 20);
this.createClassObject(mx.controls.Button, "my_bt", 30, {label: "Scroll"});
my_txt.wordWrap = true;
my_bt.move(300, 100);
// Set the target text field.
my_sb.setScrollTarget(my_txt);
// Move it next to the text field.
my_sb.move(my_txt._x + my_txt._width, my_txt._y);
// Load text to display and define onData handler.
var my_lv:LoadVars = new LoadVars();
my_lv.onData = function(src:String) {
if (src != undefined) {
my_txt.text = src;
} else {
my_txt.text = "Error loading text.";
}
};
my_lv.load("http://www.helpexamples.com/flash/lorem.txt");
var scroll_listener = new Object();
scroll_listener.click = function() {
my_sb.scrollPosition = 20;
my_txt.scroll = 20;
};
my_bt.addEventListener("click", scroll_listener);
|
|
|
|