系统自带滚动条类 UIScrollBar 使用举例

import fl.controls.UIScrollBar;
import fl.controls.ScrollBarDirection;

var url:String="http://www.helpexamples.com/flash/text/lorem.txt";

var uLdr:URLLoader=new URLLoader(new URLRequest(url));
uLdr.addEventListener(Event.COMPLETE, completeHandler);

var tf:TextField = new TextField();
tf.width=320;
tf.height=140;
tf.x=10;
tf.y=10;
tf.border=true;
tf.multiline=true;
tf.wordWrap=false;
addChild(tf);

/*
    如果只需要垂直方向滚动条,那么先设置tf.wordWrap=true,然后不要添加水平滚动条即可。
*/

//水平滚动条
var hScrollBar:UIScrollBar = new UIScrollBar();
hScrollBar.direction=ScrollBarDirection.HORIZONTAL;
hScrollBar.move(tf.x, tf.y + tf.height);
hScrollBar.width=tf.width;//一定要设置和文本框一样宽,不然不美观
hScrollBar.scrollTarget=tf;
addChild(hScrollBar);

//垂直滚动条
var vScrollBar:UIScrollBar = new UIScrollBar();
vScrollBar.direction=ScrollBarDirection.VERTICAL;
vScrollBar.move(tf.x + tf.width, tf.y);
vScrollBar.height=tf.height;//一定要设置和文本框一样高,不然不美观
vScrollBar.scrollTarget=tf;
addChild(vScrollBar);

function completeHandler(event:Event):void {
	tf.text=event.target.data;
	hScrollBar.update();
	vScrollBar.update();
}

原文地址:https://www.cnblogs.com/leon3286/p/1783856.html