Need help on infinate loop script

i’m trying to do an infinate loop for my m.clip.the looping part does not want to loop…it loops back to my firrst frame even though there are two same picture in the movie clip…here’s a sample of what i use for the infinate loop script…

[COLOR=Blue]function getdistance(x, y, x1, y1) {
var run, rise;
run = x1-x;
rise = y1-y;
return (_root.hyp(run, rise));
}
function hyp(a, b) {
return (Math.sqrt(aa+bb));
}
MovieClip.prototype.reset = function() {

width = 480;
height = 280;
	var dist, norm;
this.x = this._x;
this.y = this._y;
this.speed = Math.random()*4+2;
this.targx = Math.random()*width+10;
	this.targy = Math.random()*height+10;
	dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
norm = this.speed/dist;
this.diffx = (this.targx-this.x)*norm;
this.diffy = (this.targy-this.y)*norm;

};
MovieClip.prototype.move = function() {
if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
this.x += this.diffx;
this.y += this.diffy;
} else {
this.x = this.targx;
this.y = this.targy;
if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.reset();
this.t = 0;
}
}
this._x = this.x;
this._y = this.y;
}
stop();[/COLOR]

These script are put on the top layer.And this following script is for the movie clip.

[COLOR=Blue]onClipEvent (load) {
xcenter = 250;
speed = 1/10;
}
onClipEvent (enterFrame) {
if (_root._ymouse>30 && _root._ymouse<280) {
var distance = _root._xmouse-xcenter;
_x += (distance*speed);
if (_x>0) {
_x = -703;
}
if (_x<-703) {
_x = 0;
}
}
}[/COLOR]

i dunno why it does not work…so anyone who knows what wrong…pleease do kelp…

[color=#0000ff]just off the cuff-[/color]
[color=#0000ff]this seems wrong, or more like unnecessary.[/color]
//
[color=#0000ff]if (!this.t) {
this.t = getTimer();
}
if (getTimer()-this.t>1000) {
this.reset();
this.t = 0;
}[/color]
[color=#0000ff]//[/color]
[color=#0000ff]whats in getTimer()?[/color]
[color=#0000ff]intervals are more efficient and the more ‘logical’ way to do timing.[/color]
[color=#0000ff][/color]
[color=#0000ff]//this would create a timer set to time every second, and execute the getdistance function with the code params specified in values1-4[/color]
[color=#0000ff][/color]
[color=#0000ff]function setTimer(){[/color]
[color=#0000ff]this[“myUniqueTimerID”]= setInterval(this,“getDistance”,1000,value1,value2,value3,value4)[/color]
[color=#0000ff]}[/color]
[color=#0000ff]//this would kill the timer and stop execution[/color]
[color=#0000ff]function killTimer(){[/color]
[color=#0000ff]clearInterval(this[“myUniqueTimerID”])[/color]
[color=#0000ff]}[/color]
[color=#0000ff][/color]
[color=#0000ff]2 things-[/color]
[color=#0000ff]1. using intervals, there is no need to check for time elapsed and set it the interval more than once (unless killing it, where you would restart it again) - basically set it once and it will always run. remove the ‘buggy’ timer check that is in there. even if this doesnt fix your issue, that code is not efficiently/well written (no insult intended) and just should be re-worked at best.[/color]
[color=#0000ff][/color]
[color=#0000ff]2.unless you are operating in the realm of writting AS 2.0 classes OR MX 1 compenent objects, the key word ‘this’ when used in a timeline function will set values equal to the function it is in. (i.e. ‘this’ refers to the function itself, not the root.) change your this refs (and mine if youre not writting as classes) to _root[/color]
[color=#0000ff][/color]
[color=#0000ff]good luck-[/color]
[color=#0000ff][/color]
[color=#0000ff][/color]

also, in reading over it all again, it all should really be cleaned up. its just not efficient code by any means- and while it may work, it should be optimised for performance etc. there are better ways (and simpler) to do alot of what you are doing right there. the biggest problem in coding anything is over-complication of solutions. i suggest going over it all again once you get it to work and look for ways you can really streamline it down. i dont want to go into it all here. but if you want to ask, feel free.
again, good luck-