Thanks you for your patience.

I assure you I am reading your replies and attempting to act on your advice.

With regards the time, my movie is running at 30FPS therefore I was under the impression that the largest time slot was 1/30 seconds. I assume that the "actionLoop" function (see below) is being called 30 times per second.  Please can you explain this.

I thought my loop was correct as when I traced which balls it was comparing it had the following:

[code]

firstBallRef = ball1
secondBallRef = ball2
firstBallRef = ball1
secondBallRef = ball3
firstBallRef = ball1
secondBallRef = ball4
firstBallRef = ball1
secondBallRef = ball5
firstBallRef = ball2
secondBallRef = ball3
firstBallRef = ball2
secondBallRef = ball4
firstBallRef = ball2
secondBallRef = ball5
firstBallRef = ball3
secondBallRef = ball4
firstBallRef = ball3
secondBallRef = ball5
firstBallRef = ball4
secondBallRef = ball5

[/code]

I have moved my code to do the collision detection after the code to calculate all the ball object new positions based on your recommendation:

[quote]Another issue is you are processing collision before all the particles are moving to the next time step. [/quote]

[code]function actionLoop(e:Event):void {

calculateBallObjectNewPositions()
checkForCollisions()
updateBallPositions()

}[/code]

Unfortunately I am still getting the same error (New version here http://www.mediakitchen.co.uk/physics/testFile5v2balls.html ) but assume this must be due to the dt problem as the following is an example of my variable values when the issue occurs.

[code]firstBallRef.tempX = 164.12788355997395
firstBallRef.tempY = 172.2370476331055
secondBallRef.tempX = 115.87211644002605
secondBallRef.tempY= 112.1629523668944
firstBallRef.horizontalVelocity = 9.36283073039942
firstBallRef.verticalVelocity = -4.751832309742385
secondBallRef.horizontalVelocity = -9.36283073039942
secondBallRef.verticalVelocity = -18.44816769025763
firstBallRef = ball1
secondBallRef = ball3
firstBallRef = ball1
secondBallRef = ball4
firstBallRef = ball1
secondBallRef = ball5
firstBallRef = ball2
secondBallRef = ball3
firstBallRef = ball2
secondBallRef = ball4
dxy = 27.020217899991174
cs = 0.8929566611667419
sc = -0.4501426454780135
vp1 = -0.056295059772248024
vp2 = 0
dt = -17.404406425230103
firstBallRef.tempX = -70.12509047107508
firstBallRef.tempY = -194.96160633456583
secondBallRef.tempX = 325.9972069111011
secondBallRef.tempY= 407.12455870146016
firstBallRef.horizontalVelocity = 1.3239575671590866
firstBallRef.verticalVelocity = -0.8017997994089945
secondBallRef.horizontalVelocity = -10.686788297558504
secondBallRef.verticalVelocity = -17.646367890848634[/code]


Note that the position of secondBallRef jumps from being x = 115 to x = 407, a very large movement and hence the issue I am experiencing.

Here is my updated code:

[code]function actionLoop(e:Event):void {

calculateBallObjectNewPositions()
checkForCollisions()
updateBallPositions()

}





function calculateBallObjectNewPositions():void {


var howManyBallObjects:Number = objGame.ballObjects.length;

for (var i:Number = 0; i < howManyBallObjects; i++) {

var ballObject = objGame.ballObjects[i];

if (ballObject.alpha < 1) {



var newScale = ballObject.scaleX * 0.98;

ballObject.alpha = ballObject.alpha - 0.1;
ballObject.scaleX = newScale;
ballObject.scaleY = newScale;   

if (ballObject.alpha <= 0) {
       
            ballObject.horizontalVelocity = 0;
ballObject.verticalVelocity = 0;
       
            continue;

        } // end if
       

}


var V = (ballObject.horizontalVelocity * ballObject.horizontalVelocity) + (ballObject.verticalVelocity * ballObject.verticalVelocity);

    if (V == 0)
    {
        continue;
    } else {



}

    V = Math.sqrt(V);

    var k = (V - objGame.dV) / V;


    if (k < 0)
    {
        k = 0;
    } // end if

    ballObject.horizontalVelocity = ballObject.horizontalVelocity * k;
    ballObject.verticalVelocity = ballObject.verticalVelocity * k;

ballObject.tempX = ballObject.tempX + ballObject.horizontalVelocity;
ballObject.tempY = ballObject.tempY + ballObject.verticalVelocity;

}



}



function checkForCollisions():void {

objGame.numTotalBalls = 5;

for (var j:Number = 0; j < objGame.numTotalBalls; j++) {

var firstBallObject = objGame.ballObjects[j];
for (var f:Number = (j + 1); f < objGame.numTotalBalls; f++) {

var otherBallMC = objGame.ballObjects[f];

checkForCollisionWithBall(firstBallObject, otherBallMC);

}

}


}


function checkForCollisionWithBall(firstBallRef:MovieClip, secondBallRef:MovieClip):void {

trace ("firstBallRef = " + firstBallRef.instanceNameValue);
trace ("secondBallRef = " + secondBallRef.instanceNameValue);
 
  var dx = secondBallRef.tempX - firstBallRef.tempX // horizontal distance between the 2 balls
  var dy = secondBallRef.tempY - firstBallRef.tempY // vertical distance between the 2 balls
 
   
  var dxy = (dx * dx) + (dy * dy)
 
  if (dxy < 0.00001) { 
 
    return
 
  }
 
 
 
  if (dxy < objGame.D2) {
 
    // --------------------
    // We have a collision!
    // --------------------
   
    // ------------------------------------------------------------------------------
    // We now perform the square root to calculate the distance between the two balls
    // ------------------------------------------------------------------------------
   
    dxy = Math.sqrt(dxy)
   
    var cs = dx/dxy
    var sc = dy/dxy

trace ("dxy = " + dxy);

trace ("cs = " + cs);
trace ("sc = " + sc);
   
    // -----------------------------------------------------------
    // Calculate component of velocity in the direction of (dx,dy)
    // -----------------------------------------------------------
   
    var vp1 = firstBallRef.horizontalVelocity * cs + firstBallRef.verticalVelocity * sc
    var vp2 = secondBallRef.horizontalVelocity * cs + secondBallRef.verticalVelocity * sc
   
    trace ("vp1 = " + vp1);
trace ("vp2 = " + vp2);
 
    var dt = (objGame.D + objGame.D - dxy) / (vp1 - vp2)
   
   
   
    firstBallRef.tempX = firstBallRef.tempX - (firstBallRef.horizontalVelocity * dt)
    firstBallRef.tempY = firstBallRef.tempY - (firstBallRef.verticalVelocity * dt)
   
   
   
   
    secondBallRef.tempX = secondBallRef.tempX - (secondBallRef.horizontalVelocity * dt)
    secondBallRef.tempY = secondBallRef.tempY - (secondBallRef.verticalVelocity * dt)
   
   
   
    dx = secondBallRef.tempX - firstBallRef.tempX // horizontal distance between the 2 balls
    dy = secondBallRef.tempY - firstBallRef.tempY // vertical distance between the 2 balls
   
    var distance = Math.sqrt(dx * dx + dy * dy)
    var ax = dx/distance
    var ay = dy/distance
   
   
   
    var va1 = (firstBallRef.horizontalVelocity * ax + firstBallRef.verticalVelocity * ay)
    var vb1 = (-1 * firstBallRef.horizontalVelocity * ay + firstBallRef.verticalVelocity * ax)
   
    var va2 = (secondBallRef.horizontalVelocity * ax + secondBallRef.verticalVelocity * ay)
    var vb2 = (-1 * secondBallRef.horizontalVelocity * ay + secondBallRef.verticalVelocity * ax)
   
   
   
    var vaP1 = va1 + (1 + 1) * (va2 - va1)/(1 + 1/1)
    var vaP2 = va2 + (1 + 1) * (va1 - va2)/(1 + 1/1)
   
   
    firstBallRef.horizontalVelocity = vaP1 * ax - vb1 * ay
    firstBallRef.verticalVelocity = vaP1 * ay + vb1 * ax
 
   
    secondBallRef.horizontalVelocity = vaP2 * ax - vb2 * ay
    secondBallRef.verticalVelocity = vaP2 * ay + vb2 * ax
   
   
   
    firstBallRef.tempX = firstBallRef.tempX + firstBallRef.horizontalVelocity * dt
    firstBallRef.tempY = firstBallRef.tempY + firstBallRef.verticalVelocity * dt
   
    secondBallRef.tempX = secondBallRef.tempX + secondBallRef.horizontalVelocity * dt
    secondBallRef.tempY = secondBallRef.tempY + secondBallRef.verticalVelocity * dt

trace ("dt = " + dt);

trace ("firstBallRef.tempX = " + firstBallRef.tempX);
trace ("firstBallRef.tempY = " + firstBallRef.tempY);

trace ("secondBallRef.tempX = " + secondBallRef.tempX);
trace ("secondBallRef.tempY= " + secondBallRef.tempY);

trace ("firstBallRef.horizontalVelocity = " + firstBallRef.horizontalVelocity);
trace ("firstBallRef.verticalVelocity = " + firstBallRef.verticalVelocity);

trace ("secondBallRef.horizontalVelocity = " + secondBallRef.horizontalVelocity);
trace ("secondBallRef.verticalVelocity = " + secondBallRef.verticalVelocity);

 
  }
 
}


function updateBallPositions() {

var howManyBallObjects:Number = objGame.ballObjects.length;

for (var i:Number = 0; i < howManyBallObjects; i++) {

var ballObject = objGame.ballObjects[i];

ballObject.x = ballObject.tempX;
ballObject.y = ballObject.tempY;
}



}




[/code]

It is so frustrating that this works 90% of the time.

Many thanks for your help

Paul