Hi everybody,
I’m building a touchscreen project that consists of flash and max/msp using Olaf Matthes flashserver as bi-directional control.
Soooo…I’m wondering how I create a function in flash that will provide me with the distance of a concentric circle, so that as it grows I can use trace() to give me a constant stream of it’s x & y coordinates?
I’ve also implemented a collision detection between two or more circles for the purpose of an overlap function. Trouble being that it’s not quite working properly. I want the overlap function for the purpose of morphing sounds between the intersecting parts of the circles.
I’d really appreciate any help anyone could offer with this. Sorry if it’s clear as mud.
Here’s the code I’m using:
/*
flash frontend - simple flash gui for Max/MSP
(c) 2002 - 2003 Olaf Matthes <olaf.matthes@gmx.de>
http://www.nullmedium.de/dev/flashserver/
*/
fscommand(“allowscale”, false);
fscommand(“fullscreen”, false);
function maxsendvars (symbol, value) {
fudi = symbol + " " + value + ";"
max.send(fudi);
}
server = "localhost";
port = 31337;
_root.max = new XMLSocket();
max.connect(server, port);
max.onConnect = onMaxConnect;
max.onClose = onMaxClose;
max.onData = onMaxData;
function onMaxConnect (success) {
if (success) {
msg = "Connected to "+server+" on port "+port;
} else {
msg = "There has been an error connecting to "+server+" on port "+port;
}
}
function onMaxClose () {
msg = "Lost connection to "+server+" on port "+port;
}
/* receive data from flashserver */
function onMaxData(doc) {
msg = "Received data from server: " + doc;
}
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(){ /
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 + “;”);
_root.max.send("; y_value " + _root._ymouse + “;”);
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++) {
// dont check with ourself
if(i == j) continue;
var dest:MovieClip = circles[j]; //Variable: dest [j]
var touching:Number = checkOverlap(src,dest);
if(touching) //If they are touching [true] show results on flashes output
{
trace("Circles : " + src._x + " " + src._y + " : " + dest._x + " " + dest._y + " overlap");
}
}
}
}
function checkOverlap(c1:MovieClip, c2:MovieClip):Number
{
// Trigonometry: 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) //If distances is more than circle 1 + circle 2 width
{
return Number(true)//Overlap is true
}
else //Otherwise
{
return Number(false); //Overlap is false
}
}
PS I’m still finding my feet with all this scripting malarky so don’t be too hasty to pick on me if I’ve done something wrong