Syncing Code With FrameRate

Hey guys,

I’m having a problem with what I think might be a sync with framerate problem.

package  {	
	import flash.display.MovieClip;	
	import flash.events.Event;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	
	public class Curves extends MovieClip{
		
		//GlobalSpeed
		public static var GlobalSpeed:int = 1;
		
		//Blitting variables
		public var CANVAS_BD:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x00FF0F);
		public var CANVAS_BITMAP:Bitmap = new Bitmap(CANVAS_BD);
		public var BACKGROUND_BD:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x000000);
		public var DOTSHEET1:DotSheet = new DotSheet();
		
		//DotsArray properties
		public var DotDiameter:int = 40;//Should be a factor of stage.stageHeight
		public var DotSpacing:int = DotDiameter;//Distance between Dots Y values
		public var MaxVerticalDots:int = stage.stageHeight/DotDiameter;//Max dots that can be fit on screen vertically
		public var DotsArray:Array = new Array(MaxVerticalDots + 1);//+1 for one Dot to be off screen


		//Cosine/sine function: Rotated -90 degrees into f(y)
		public var PeriodFactor:int;
		public var AmplitudeFactor:int;
		public var FunctionOffset:int;
		
		//Populate DotsArray with Dots and set (x/y)
		public function SetUpDotsArray() {
			for(var i = 0; i < DotsArray.length; i++) {
				if(i == 0) {
					DotsArray[0] = new Dot(DotDiameter/2, 0xFFFFFF);
					DotsArray[0].x = stage.stageWidth/2;
					DotsArray[0].y = -DotDiameter;
				}
				if(i > 0) {
					DotsArray* = new Dot(DotDiameter/2, 0x000000);
					DotsArray*.x = stage.stageWidth/2;
					DotsArray*.y = DotsArray[i - 1].y - DotSpacing;
				}
				addChild(DotsArray*);
			}
		}
		
		public function SetDotCoordinates(d:Dot) {
			//First Dot, DotsArray[0], is treated differently
			if(DotsArray.indexOf(d) == 0) {
				//When zero needs to come back up top
				if(DotsArray[0].y >= stage.stageHeight) {
					//It's y value should follow that of the last element in the array
					DotsArray[0].y = -DotDiameter;
				}
			}
			if(DotsArray.indexOf(d) > 0) {
				if(DotsArray[DotsArray.indexOf(d)].y >= stage.stageHeight) {
					DotsArray[DotsArray.indexOf(d)].y = DotsArray[DotsArray.indexOf(d) - 1].y - DotSpacing;
				}
			}
		}
		
		public function MoveDots() {
			//Set coordinates and move
			for(var j = 0; j < DotsArray.length; j++) {
				SetDotCoordinates(DotsArray[j]);
				DotsArray[j].y += GlobalSpeed;
			}
		}


		public function Curves() {
			addEventListener(Event.ENTER_FRAME, MainLoop);
			addChild(CANVAS_BITMAP);
			SetUpDotsArray();
		}
		
		public function MainLoop(e:Event) {
			MoveDots();
			trace(DotsArray[0].y);
		}


	}
	
}



What I am trying to do is get these dots to loop infinitely butted up next to eachother but for some reason a gap starts forming between the first element of EnemyArray and the last element. When I change the speed and/or the framerate it only gets worse and I would ideally like to have it work regardless of framerate or speed. I hope this makes sense.