Playing around further I came up with the following functions:
PHP Code:
function distance(element1,element2){
a=abs (element1.x - element2.x);
b=element1.y - element2.y;
return sqrt (a*a+b*b);
}
function collide(distance,width){
return distance<=width
}
put those in your starting script then when you want to check for a hit do this
PHP Code:
dist=root.distance(element ("ball1"),element ("ball2"));
hit=root.collide(dist,24);
Or better yet let the function do all the work:
PHP Code:
function C_collide(element1,element2)
{
//get width of both elements
width1=(element1.getBounds().xMax-element1.getBounds().xMin)-5
width2=(element2.getBounds().xMax-element2.getBounds().xMin)-5
//get distance
a=element1.x - element2.x;
b=element1.y - element2.y;
dist= sqrt (a*a+b*b);
//account for different sizes
width=(width1/2)+(width2/2);
//check distance and size
//return t/f
return dist<=width
}
not sure why I had to subtract 5 from the widths but I found I did.
then call this function like this:
PHP Code:
hit=root.C_collide(element ("ball1"),element ("ball2"));
Hope you find this useful!