Overlap function help

Hi, wonder if anyone could help me with this problem.

Basically the following code is creating concentric circles.

I’ve got a collision detection and overlap function script at the end which is telling me if two or more circles have interacted with another.

What i’m basically after is for flash to give me a string of numbers to tell me how much of an overlap is occuring.

I know the end of this script is wrong - I’m getting a boolean outcome instead of a number, I think “return true;” needs to be “return dist;” and “return false;” should be “return 0;” but if I try and change that then I get:

“The Expression returned must match the function’s return type”

and if I try and change :boolean to :number in that function then I get:

“Type mismatch in assignment statement: Number where Boolean is required”

Any ideas?

Heres my script:

circles = new Array();

circle._visible = false;

var drawCFlag:Boolean = true;

listener = new Object();
listener.onMouseDown = function(){
_root._quality = “MEDIUM”;
instructions._visible = false;
msDown = true;
}
listener.onMouseUp = function(){
msDown = false;
drawCFlag = true;
}
Mouse.addListener(listener);

var circleCount = 0;
this.onEnterFrame = function(){ // updates every frame
if (msDown==true && drawCFlag == true){
circleCount++;
var newCircle:MovieClip = _root.circle.duplicateMovieClip(“circle”+circleCount, circleCount);
circles.push(newCircle);
_root[“circle”+circleCount]._x = _root._xmouse;
_root[“circle”+circleCount]._y = _root._ymouse;
trace ("[x value= " + _root._xmouse + “]”)
trace ("[y value= " + _root._ymouse + “]”)
trace ("[circleCount= " + circleCount + “]”)
trace ("[circles size = " + circles.length + “]”)
_root.max.send("; x_value " + _root._xmouse + “;”); //send info to max/msp
_root.max.send("; y_value " + _root._ymouse + “;”); //send info to max/msp
drawCFlag = false;
}
andgo();
}

function andgo(){

//Collision detection:
for(var i:Number = 0;i < circles.length;i++)
{
var src:MovieClip = circles*;
for(var j:Number = 0;j < circles.length;j++)
{

		if(i == j) continue;
		var dest:MovieClip = circles[j]; 
		var touching:Boolean = checkOverlap(src,dest);
		if(touching)
		{
			trace("Circles : " + src._x + "   " + src._y + " : " + dest._x + "   " + dest._y + " overlap");  
		}
		//else
		//{
		//trace("No overlap between : " + src + " : " + dest);
	}
}

}

function checkOverlap(c1:MovieClip, c2:MovieClip):Boolean
{
// distance between centers
var dx:Number = c2._x - c1._x;
var dy:Number = c2._y - c1._y;
var dist:Number = Math.sqrt( (dx*dx) + (dy * dy) );

if(dist &lt; c1._width + c2._width)
{
	return true;
	}
	else
	{
	return false;

if true
myvar = 1
if false
myvar =0

???

couldn’t you just have a function that reads the distance, or stick the distance in a variable when they collide for the first time?

Ok I’ve managed to change the script so that I no longer receive the error messages like so:

function checkOverlap(c1:MovieClip, c2:MovieClip):Number
{
//distance between centers
var dx:Number = c2._x - c1._x;
var dy:Number = c2._y - c1._y;
var dist:Number = Math.sqrt( (dx*dx) + (dy * dy) );

if(dist &lt; c1._width + c2._width)
{
	return Number(true)
	}
	else
	{
	return Number(false);
}

}

but this still doesn’t give me the numbers that I need.

Flash is outputting something like this:

[circles size = 1]
[x value= 250]
[y value= 235]
[circleCount= 2]
[circles size = 2]
Circles : 252 136 : 250 235 overlap
Circles : 250 235 : 252 136 overlap
Circles : 252 136 : 250 235 overlap
Circles : 250 235 : 252 136 overlap
Circles : 252 136 : 250 235 overlap
Circles : 250 235 : 252 136 overlap
Circles : 252 136 : 250 235 overlap
Circles : 250 235 : 252 136 overlap
Circles : 252 136 : 250 235 overlap
Circles : 250 235 : 252 136 overlap
Circles : 252 136 : 250 235 overlap
Circles : 250 235 : 252 136 overlap

It’s repeating the same sequence of numbers (the x & y value of src and dest) but I need to know how to calculate the intersection between these two (or more circles).

Also thanks for replying randomagain