my scrollbar

代码

scrollBar.addEventListener(MouseEvent.MOUSE_DOWN,downBar);
//滚动条鼠标按下
scrollBar.addEventListener(MouseEvent.MOUSE_MOVE,moveBar); //滚动条滚动
scrollBar.addEventListener(MouseEvent.MOUSE_UP,upBar); //滚动条鼠标弹起
scrollBar.height = txt.height * barLine.height / txt.textHeight; //初始化滚动条的高度
var isDown:Boolean; //滚动条鼠标是否按下
var mousey:Number; //鼠标y坐标
function downBar(e:MouseEvent):void{
isDown
= true; //鼠标按下
mousey = mouseY; //鼠标y坐标初始值
}
function upBar(e:MouseEvent):
void{
isDown
= false; //鼠标弹起
}
function moveBar(e:MouseEvent):
void{
if(isDown){
if(scrollBar.y < barLine.y){ //滚动条到最顶端时
scrollBar.y = barLine.y;
}
else if(scrollBar.y > (barLine.y + barLine.height - scrollBar.height)){
//滚动到最底端时
scrollBar.y = barLine.y + barLine.height - scrollBar.height;
}
else{
scrollBar.y
+= (mouseY-mousey); //滚动条滚动的幅度
var hh = scrollBar.height*(mouseY-mousey) / txt.height;
//计算textfield应该滚动的幅度
txt.scrollV += hh; //滚动textfield的内容;
mousey = mouseY; //重新定义鼠标y坐标
}
}
}

 

posted @ 2010-03-01 15:53  TQ.CH  阅读(361)  评论(0编辑  收藏  举报