adobe docs上有一个很好的例子。
您可能缺少的行是。
mySb.scrollTarget = myTxt;
请注意,如果您使用 flash,则需要将 UIScrollBar 的实例拖到库中。
import flash.net.URLLoader;
import fl.controls.UIScrollBar;
import flash.events.Event;
var myTxt:TextField = new TextField();
myTxt.border = true;
myTxt.width = 200;
myTxt.height = 16;
myTxt.x = 200;
myTxt.y = 150;
var mySb:UIScrollBar = new UIScrollBar();
mySb.direction = "horizontal";
// Size it to match the text field.
mySb.setSize(myTxt.width, myTxt.height);
// Move it immediately below the text field.
mySb.move(myTxt.x, myTxt.height + myTxt.y);
// put them on the Stage
addChild(myTxt);
addChild(mySb);
// load text
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://www.helpexamples.com/flash/lorem.txt");
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadcomplete);
function loadcomplete(event:Event) {
// move loaded text to text field
myTxt.text = loader.data;
// Set myTxt as target for scroll bar.
mySb.scrollTarget = myTxt;
}