[size=1]Hi,
I’ve built a script for a dynamically created movieclip scroller that eases smoothly when scrolled. It’s working great, but I’m having a bit of trouble with the positioning of the content after the scrollbar has been pressed/dragged. I believe that the problem may be in the equation for the Ypos variable (inside the ‘updateScrollbar()’ function)…but I’m not sure. Can anyone help with suggestions for optimization of this script? i think it’s a valuable one to have in a script library…once it’s working 100% properly.[/size]
[size=1]Please see the script below. Note that on the stage, there are 2 movieclips already existent: “content1” and “mask1”. If you’d like to see the .fla or experiment with it, you may download it here:[/size]
[size=1]http://www.gabewatkins.com/grab/scroller.zip[/size]
[size=1]Any help is much appreciated![/size]
[size=1]------------------------[/size]
[size=1][color=royalblue]mc = content1;
mask = mask1;
scrollOffset = 10;[/color][/size]
[size=1][color=royalblue]scrollIt(mc, mask, scrollOffset);[/color][/size]
[size=1][color=royalblue]function addScrollElements(mask, offset) {
st = attachMovie(“scrolltrack”, “scrolltrack”, 0); // attach the scrolltrack mc
st._x = mask._x+(mask._width+offset); // position it ‘offsetR’ number of pixels to the right of the mask
st._y = mask._y; // position it even with the top of the mask
st._height = mask._height; // set the height equivalent to the mask’s height
sb = attachMovie(“scrollbar”, “scrollbar”, 1); // attach the scrollbar mc
sb._x = st._x // position it’s ‘x’ equivalent to the scrolltrack’s ‘x’
sb._y = st._y; // position it at the top of the scrolltrack
diff_y = mask._height-sb._height;
bounds = mask.getBounds(this);
top = bounds.yMin;
bottom = bounds.yMax-(sb._height);
}[/color][/size]
[size=1][color=royalblue]function addEvents(mc){
mc.onEnterFrame = function() {
Ysquare = this._y;
Ydiff = Ypos-Ysquare;
Ymove = Ydiff/6; //modify easing out speed here
this._y = Ysquare+Ymove;
}
sb.onMouseDown = function() {
startDrag(this, false, this._x, top, this._x, bottom);
scrolling = true;
}
sb.onMouseUp = function() {
stopDrag();
scrolling = false;
}
sb.onEnterFrame = function() {
if (scrolling) {
updateScrollbar(mc, mask);
done = false;
} else if (!done) {
done = true;
}
}
}[/color][/size]
[size=1][color=royalblue]function updateScrollbar(mc, mask) {
Ypos = -(((sb._y-top)/diff_y)*(mc._height-mask._height));
}[/color][/size]
[size=1][color=royalblue]function scrollIt(mc, mask, offset) {
addScrollElements(mask, offset);
addEvents(mc);
}[/color][/size]
[size=1]------------------------[/size]
[size=1]Thank you!
[/size]