# Strange logic problem

**URL:** <https://forum.kirupa.com/t/strange-logic-problem/263706>\
**Category:** flash\
**Created:** [June 18, 2008, 2:45pm UTC](https://forum.kirupa.com/t/strange-logic-problem/263706 "2008-06-18T14:45:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bizley](https://avatars.discourse-cdn.com/v4/letter/b/a5b964/32.png) [@bizley](https://forum.kirupa.com/u/bizley)\
**Post date:** [June 18, 2008, 2:45pm UTC](https://forum.kirupa.com/t/strange-logic-problem/263706/1 "2008-06-18T14:45:07Z")

</div>

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 … 🙂  
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](http://rapidshare.com/files/121196795/moving_symbols.fla.html) ( Flash CS3 ), the swf file: [http://img59.imageshack.us/my.php?image=movingsymbolsip3.swf](http://img59.imageshack.us/my.php?image=movingsymbolsip3.swf), and the code:

```auto

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 😃 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 😃 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 ! 🙂
