Scrollbar-Button jitters when reaching maximum/minimum
I'm开发者_高级运维 building a scrollbar.
On MouseDown I start a repeating timer to position the Scrollbar-Button(Slider). When it reaches minimum/maximum it jitters (switching between min/max and stage.mouseY…) How can I prevent that?
private function onTime(e:TimerEvent):void
{
if(this._scrollBtn.y < min)
{
this._scrollBtn.y = min;
}
else if(this._scrollBtn.y > max-this._scrollBtn.height)
{
this._scrollBtn.y = max-this._scrollBtn.height;
}
else
{
this._scrollBtn.y = stage.mouseY;
}
}
I'd recommend listening for the MouseEvent.MOUSE_MOVE
instead of using a timer, that way you're only doing work if and when the mouse is moving.
Your problem is likely that your validating the position of the scroll handle "after" moving it, letting it be out of bounds for a while before the next update comes and moves it back.
There's also no reason in having this
everywhere, unless it's explicitly needed.
private function onTime(e:TimerEvent):void
{
_scrollBtn.y = stage.mouseY;
if(_scrollBtn.y < min)
{
_scrollBtn.y = min;
}
else if(_scrollBtn.y > max - _scrollBtn.height)
{
_scrollBtn.y = max - _scrollBtn.height;
}
}
精彩评论