Object Wrap

I’ve been fooling with a horizontal scroller. Attached is the fla. and code below.

I’m not too good with the math . . .

It seems to scroll ok forwards and back, BUT, when the strip repeats (so #1 comes back around again after #5) it seems to skips right to #2

Also, it would be cool if it would jump to the nearest full square when you stop cranking.
hmmm . . . any thoughts?

Thanks!!

MovieClip.prototype.objectWrap = function(MinX,MaxX,MinY,MaxY){
// check the X.
if(this._x >= MaxX){
this._x -= MaxX;
}else if(this._x <= MinX){
this._x += MaxX;
}
/////check the Y.
if(this._y >= MaxY){
this._y -= MaxY;
}else if(this._y <= MinY){
this._y += MaxY;
}
};

mc.btn.onPress = function(){
scrolling = true;
//mc.btn is the crank and buton–mc is just the crank
}
mc.btn.onRelease = mc.btn.onReleaseOutside = function(){
scrolling = false;
}
onEnterFrame = function(){
if(scrolling){
var dx=_xmouse-mc._x;
var dy=_ymouse-mc._y;
var r = Math.atan2(dy,dx);
if(r >= Math.PI2) r-=Math.PI2;
if(r < 0)r+=Math.PI2;
var oa = a;
a = (r
180)/Math.PI;
var da = a-oa;
mc._rotation=a;
if(Math.abs(da) > 180) da = 0;

ball2._x += da&lt;&lt;1;
ball2._y += Math.cos(r)*0;

ball2.objectWrap(-352,352,-352,352);
//352 is the number of pixels that pass through the mask before it should repeat---each number square is 88 pixels wide
}

};