 # Mouse events arent being triggered properly?

Hello again everyone… Another problem, this ones had me stumped for hours…
Ive made a program upto the point where i can create circular sprites(balls), and put them in an array…
In the next frame, the user is supposed to be able to impart velocity to the balls by dragging and releasing the mouse … Im having problems with this… this is my code:

``````
import com.coreyoneil.collision.CollisionGroup;
var collider = new CollisionGroup();

var vx:Array = [];
var vy:Array = [];
var ax:Array = [];
var ay:Array = [];

var currentX:Number = 0;
var lastX:Number = 0;
var currentY:Number = 0;
var lastY:Number = 0;

//Will store index of the object being currently dragged
var currentIndex:Number = -1;
var currentObject:Object = null;

for (var i:uint=0; i<circObjects.length; i++)
{
vx* = 0;
vy* = 0;
ax* = 0;
ay* = 0;
}

function EnterFrame(e:Event)
{
lastX = currentX;
currentX = mouseX;
lastY = currentY;
currentY = mouseY;
if (currentIndex !=-1)
{
vx[currentIndex] = currentX - lastX;
vy[currentIndex] = currentY - lastY;
for (var j:uint=0;j<circObjects.length;j++)
{
if (j != currentIndex)
{
vx[j] += ax[j];
vy[j] += ay[j];
circObjects[j].x +=vx[j];
circObjects[j].y +=vy[j];
}
}
}
else
{
for (var k:uint=0;k<circObjects.length; k++)
{
vx[k] += ax[k];
vy[k] += ay[k];
circObjects[k].x += vx[k];
circObjects[k].y += vy[k];
}
}
}

function onUp(e:MouseEvent)
{
currentIndex = -1;
trace ("On Up")
}

function onMove(e:MouseEvent)
{
if (currentIndex!=-1 )//&& isDragging)
{
currentObject.x = mouseX;
currentObject.y = mouseY;
trace ("On Move")
}
e.updateAfterEvent();
}

function onDown(e:MouseEvent)
{
//first circle created is instance 4, second is instance 5 etc..
var target:Number = Number (e.target.name.substr(8,9) );
target = target - 4;
currentIndex = target;
currentObject = circObjects[currentIndex];
trace ("On Down");

}

``````

This code only works with one object added on stage (i.e one object in circObjects).
If i add more than one object the balls arbitrarily seem to jump some distance ahead when I click on them, and follow my mouse around even when Im not clicking…

I think its a problem with lastX, currentX , lastY, currentY but I cant understand it…

Oh and dont worry about how i get currentIndex in onDown, there are 3 objects in the previous frame, so the first ball i make is called instance4, the second instance5 and so on…