User Guide

UIScrollBar.scroll 1405
Example
The following example implements Usage 1 and creates a listener object called sbListener
with a
scroll event handler:
/**
Requires:
- UIScrollBar component in library
*/
this.createTextField("my_txt", 10, 10, 20, 200, 100);
my_txt.wordWrap = true;
this.createClassObject(mx.controls.UIScrollBar, "my_sb", 20);
// Set the target text field.
my_sb.setScrollTarget(my_txt);
// Size it to match the text field.
my_sb.setSize(16, my_txt._height);
// Move it next to the text field.
my_sb.move(my_txt._x + my_txt._width, my_txt._y);
// Create listener object.
var sbListener:Object = new Object();
sbListener.scroll = function(evt_obj:Object){
// Insert code to handle the "scroll" event.
trace("text is scrolling");
}
// Add listener.
my_sb.addEventListener("scroll", sbListener);
// 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");
The following code implements Usage 2. The code is attached to the UIScrollBar component
instance and sends a message to the Output panel when the user clicks the scroll bar. The
on() handler must be attached directly to the UIScrollBar instance.
on (scroll) {
trace("UIScrollBar component was clicked");
}