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 < c1._width + c2._width)
{
return true;
}
else
{
return false;