# Mouse Scroller Algorithm question

I have a mouse controlled scroller which I've fashioned from Lee Brimelow's excellent tutorial. I'm at the stage now where I want to add more thumbnails to the scroller's content area, though when I do, the scroller will not scroll any more than 8 thumbnails in either direction.

My question is (for those of you who are way better at Math, than me) how do I complete the algorithm to compensate for adding more than just 8 thumbnails - into, say, 30 thumbnails and have the scrolling behavior always show the last or first thumbnail when the mouse is at either side of the scroller movieclip?

private function scrollPanel(e:MouseEvent):void {

var xdist:Number = mouseX - 250;
//_xContainer is an mc which holds the thumbnail images
TweenLite.to(_xContainer, 0.3, { x:Math.round(-xdist)});

}

• ###### 1. Re: Mouse Scroller Algorithm question

when the mouse is at one extreme position the thumbnails should be at an extreme position and when the mouse is at the other extreme the thumbs should be at their other extreme.  then use linear interpolation for all other mouse positions.

so, for example, if you want mouseX=0 to correspond to the thumbnail parent (_xContainer) being at zero (assuming a left edge reg pt) and you want mouseX=stage.stageWidth to correspond to -_xContainer.width+stage.stageWidth, declare and type your variables and use:

findParamsF(0,0,stage.stageWidth,stage.stageWidth-_xContainer.width);

function findParamsF(x1,y1,x2,y2){

m=(y1-y2)/(x1-x2);

b=y1-m*x1;

}

private function scrollPanel(e:MouseEvent):void {

var xdist:Number = m*mouseX + b;
//_xContainer is an mc which holds the thumbnail images
TweenLite.to(_xContainer, 0.3, { x:Math.round(-xdist)});

}