Horizontal Fullscreen Scrollbar Problem

Hey Everyone,

I’m coding a horizontal scrollbar that will contain several movieclips. The scrollbar has a few ways to scroll through it, a traditional scrollbar (scrubber & track), a next and a previous button that will scroll from clip to clip, and finally clicking on the scrollbar track to go to that point. However the bar doesn’t full scroll back to it’s original start point and at the opposite end it scrolls a little too much past the end of the clip. The same with the next and previous buttons you click the previous button it comes up just short of the original start point and the next button goes just a little further then it should. I cant seem to figure out whats wrong with it. I realized this is kind of a hard problem to explain so I attached an fla file (CS3 & CS4).

Here is my code:


Stage.scaleMode = "noScale";
Stage.align = "TL";

import mx.transitions.Tween;
import mx.transitions.easing.*;

mask_mc._width = Stage.width - 28;

var nodeWidth:Number = 	568;
var padding:Number = 0;
var aSpeed:Number = 1; //# of seconds

// Main scrolling for all clips
function scrolling() {
	var clipwidth:Number = target_mc._width;
	var maskwidth:Number = mask_mc._width;
	var totalpos:Number = maskwidth-clipwidth;
	var max:Number = (track_mc._width+track_mc._x)-drag_mc._width;
	// Calculation for scrolling clip
	var diff:Number = (clipwidth-maskwidth)/(track_mc._width-drag_mc._width);
	var newpos:Number = 	-Math.round(difference*diff);
	var animatePos:Number;
	// drag_mc on press
	drag_mc.onPress = function() {
		// Start dragging, limit the dragging to parameters
		startDrag(this, false, track_mc._x, this._y, (track_mc._width+track_mc._x)-this._width, this._y);
		// Update scrolling clip in conjunction with the y position of the drag_mc
		this.onMouseMove = function() {
			difference = Math.abs(this._x-padding);
			newpos = -Math.round(difference*diff);
			//var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeOut, target_mc._x, newpos, aSpeed, true);
			this.onEnterFrame = function() {
				newpos = -Math.round(difference*diff);
				animatePos = Math.round((newpos-target_mc._x)/4)
				if (animatePos != 0) {
					target_mc._x += animatePos;
				} else {
					delete this.onEnterFrame;
				}
			};
		};
	};
	// On release, kill function
	drag_mc.onRelease = drag_mc.onReleaseOutside=function () {
		this.gotoAndPlay("end");
		stopDrag();
		delete this.onMouseMove;
	};
	drag_mc.onRollOver = function() {
		this.gotoAndPlay("start");
	};
	drag_mc.onRollOut = function() {
		this.gotoAndPlay("end");
	};
	// For clicking on the scroll track
	track_mc.onPress = function() {
		var xClick = _xmouse;
		if (xClick < max) {
			newpos = -Math.round(xClick*diff);
			var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeOut, drag_mc._x, xClick, aSpeed, true);
			var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeOut, target_mc._x, newpos, aSpeed, true);
		} else {
			newpos = -Math.round(max*diff);
			var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeOut, drag_mc._x, max, aSpeed, true);
			var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeOut, target_mc._x, newpos, aSpeed, true);
		}
	};
	next_mc.onRollOver = function() {
		this.gotoAndStop(2);
	};
	next_mc.onRollOut = next_mc.onReleaseOutside=function () {
		this.gotoAndStop(1);
	};
	next_mc.onPress = function() {
		if (target_mc._x>totalpos+nodeWidth) {
			var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeInOut, target_mc._x, target_mc._x-nodeWidth, aSpeed, true);
			var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeInOut, drag_mc._x, drag_mc._x+(nodeWidth/diff), aSpeed, true);
		} else {
			var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeInOut, target_mc._x, totalpos, aSpeed, true);
			var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeInOut, drag_mc._x, max, aSpeed, true);
		}
	};
	prev_mc.onRollOver = function() {
		this.gotoAndStop(2);
	};
	prev_mc.onRollOut = prev_mc.onReleaseOutside=function () {
		this.gotoAndStop(1);
	};
	prev_mc.onPress = function() {
		if (target_mc._x<-nodeWidth) {
			var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeInOut, target_mc._x, target_mc._x+nodeWidth, aSpeed, true);
			var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeInOut, drag_mc._x, drag_mc._x-(nodeWidth/diff), aSpeed, true);
		} else {
			var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeInOut, target_mc._x, padding, aSpeed, true);
			var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeInOut, drag_mc._x, padding, aSpeed, true);
		}
	};
	mouseListener = new Object();
	mouseListener.onMouseWheel = function(delta) {
		if (delta<0) {
			if (target_mc._x>totalpos+nodeWidth) {
				var moveMC:Tween = 	new Tween(target_mc, "_x", Strong.easeOut, target_mc._x, target_mc._x-nodeWidth, 0.3, true);
				var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeOut, drag_mc._x, drag_mc._x+(nodeWidth/diff), 0.3, true);
			} else {
				var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeOut, target_mc._x, totalpos, 0.3, true);
				var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeOut, drag_mc._x, max, 0.3, true);
			}
		}
		if (delta>0) {
			if (target_mc._x<-nodeWidth) {
				var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeOut, target_mc._x, target_mc._x+nodeWidth, 0.3, true);
				var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeOut, drag_mc._x, drag_mc._x-(nodeWidth/diff), 0.3, true);
			} else {
				var moveMC:Tween = new Tween(target_mc, "_x", Strong.easeOut, target_mc._x, padding, 0.3, true);
				var moveDrag:Tween = new Tween(drag_mc, "_x", Strong.easeOut, drag_mc._x, padding, 0.3, true);
			}
		}
	};
	Mouse.addListener(mouseListener);
}

scrolling();