code:

ball1x = ball1._x;

ball1y = ball1._y;

ball2x = ball2._x;

ball2y = ball2._y;

distx = ball1x-ball2x;

disty = ball1y-ball2y;

hy = Math.sqrt((distx*distx)+(disty*disty));

if (hy<radius*2+4) {

normalX = distx/hy;

normalY = disty/hy;

Vector1 = ball1.xmove*normalX+ball1.ymove*normalY;

Vector2 = ball2.xmove*normalX+ball2.ymove*normalY;

Vector3 = Vector1-Vector2;

dv0 = -0.9*Vector3;

dv1 = 0.9*Vector3;

ball1.xmove += normalX*dv0;

ball1.ymove += normalY*dv0;

ball2.xmove += normalX*dv1;

ball2.ymove += normalY*dv1;

midpointX=(ball1._x+ball2._x)/2;

midpointY=(ball1._y+ball2._y)/2;

ball1._x=midpointX + normalX*radius;

ball1._y=midpointY + normalY*radius;

ball2._x=midpointX - normalX*radius;

ball2._y=midpointY - normalY*radius;

}