Strange logic problem

Hey guys !
I am new to AS and my coding skills are not very good, but i managed somehow to create a working code ( with AS2 ) for my first project.
Well … almost … :slight_smile:
The thing is that i cant understand the reason for the problem => cant find the solution. It is a logical problem, Thats
for sure.
Here is the fla file - http://rapidshare.com/files/121196795/moving_symbols.fla.html ( Flash CS3 ), the swf file: http://img59.imageshack.us/my.php?image=movingsymbolsip3.swf, and the code:


var ballAr = new Array("ball_mc", "ball2_mc","ball3_mc")
for(i=0; i< ballAr.length; i++){
this["ballAr" + i] = new Object();
this["ballAr" + i].ballStartPointX;
this["ballAr" + i].ballStartPointY;
this["ballAr" + i].YmStartPoint;
this["ballAr" + i].XmStartPoint;
this["ballAr" + i].Ydistance;
this["ballAr" + i].Xdistance;
}
var YmEndPoint;
var XmEndPoint;
var ballSpeed = 2;
var flagH = false;
hover_btn.onRollOver = function(){
flagH = true;
for(i=0; i< ballAr.length; i++){
_root["ballAr"+i].YmStartPoint = _root._ymouse;
_root["ballAr"+i].XmStartPoint = _root._xmouse;
_root["ballAr"+i].ballStartPointX = _root[ballAr*]._x;
_root["ballAr"+i].ballStartPointY = _root[ballAr*]._y;
}
}
hover_btn.onRollOut = function(){
flagH = false;
ballSpeed = 2;
}
onEnterFrame = function(){
if(flagH)
{
for(i=0; i< ballAr.length; i++){
YmEndPoint = _root._ymouse;
XmEndPoint = _root._xmouse;
_root["ballAr"+i].Ydistance = YmEndPoint - _root["ballAr"+i].YmStartPoint;
_root["ballAr"+i].Xdistance = XmEndPoint - _root["ballAr"+i].XmStartPoint;
_root[ballAr*]._x = _root["ballAr"+i].ballStartPointX - _root["ballAr"+i].Xdistance;
_root[ballAr*]._y = _root["ballAr"+i].ballStartPointY - _root["ballAr"+i].Ydistance;
}
}
for(i=0; i< ballAr.length; i++){
_root[ballAr*]._x+=ballSpeed;
}
for(i=0; i< ballAr.length; i++){
if(_root[ballAr*]._x > 500){
_root[ballAr*]._x = 0 ;
_root["ballAr"+i].ballStartPointX = _root[ballAr*]._x;
_root["ballAr"+i].XmStartPoint = _root._xmouse;
}
if(_root[ballAr*]._x < 0){
_root[ballAr*]._x = 500;
_root["ballAr"+i].ballStartPointX = _root[ballAr*]._x;
_root["ballAr"+i].XmStartPoint = _root._xmouse;
 
}
if(_root[ballAr*]._y < 0){
_root[ballAr*]._y = 350;
_root["ballAr"+i].ballStartPointY = _root[ballAr*]._y;
_root["ballAr"+i].YmStartPoint = _root._ymouse;
 
}
if(_root[ballAr*]._y > 350){
_root[ballAr*]._y = 0;
_root["ballAr"+i].ballStartPointY = _root[ballAr*]._y;
_root["ballAr"+i].YmStartPoint = _root._ymouse;
 
}
}
}

Explaining the goals of the code -
I have 3 ( or more ) symbols on the scene. When i move the mouse, they react to the movement ( they move to the opposite direction ). When the symbols reach a certain value of X/Y, they appear at the opposite end of the scene. For example if i move the mouse to the left, the objects on the screen move to the right. If they reach the right “border”, they reappear at the left “border”.
Well … it is working, but there is a strange side effect :smiley: If i make chaotic circular movements with the mouse, ( the cursor leaves the “hover zone”, and the objects reappear several times ) all of the objects eventualy come together … its like there is a strange gravitational field between them :smiley: Cant understand the reason for that and i hope, that someone more experienced than me, can help me.
Apologies for my bad spelling and thanks for the help ! :slight_smile: