Hi everyone, I hope someone can help me with this
I’m using Flash and reacTIVision for a project but I’m having some problems. I’ve set up a webcam under a perspex sheet that fiducials are moved around on. I’ve downloaded the TUIO Flash demo from here: http://nuigroup.com/forums/viewthread/281/ and finally got it to work.
What I’d like to do is:
* Depending on the coordinates of the fiducial (I’ll define the coordinates in the code), move to a particular frame of a simple Flash animation I’ve made.
* Depending on whether a particular fiducial is present, open a flash pop-up screen and control a video (simply play or stop a video clip).
I thought this would be a simple IF statement - e.g. if fiducial with id = 2 is at coordinate (100,200) then go to frame 20.
The problem I’m having is I can’t figure out where in the code to write the extra code to do this. I’ve pasted the code from the demo below.
I’m thinking that my code should use sid, id, x, y, a but how? Or maybe it should go in the part that says “THIS IS WHERE YOU COULD DO SOMETHING COOL”?!
I feel so dumb for not being able to figure out something so simple - any help would be appreciated soooo much!! thanks
.
.
.
/**
* flosc - Flash OpenSound Control
* Ben Chun, 2002
*
* Credits:
* design and structure based on MoockComm by Colin Moock.
* server based on CommServer by Derek Clayton.
* (see TcpServer.java and TcpClient.java for more information.)
*
* Modified by Michel Maas for attaching movieclips as objects
* Adding, moving, rotating + removing functional. Also adds
* a textfield with the fiducial number on the MC.
*
* Also added cursor (fingertip) support.
*
*/
stop ();
// *** general init
var incomingUpdated = false;
incoming = "";
createEmptyMovieClip("Scene",1);
createEmptyMovieClip("Line",2);
var objectList = new Array(120);
var cursorList = new Array(120);
// here we create holders for the objects and cursor
for (var i=0;i<120;i++) {
var tuio = Scene.attachMovie("object","tuio"+i,i);
tuio.x=0;
tuio.y=0;
tuio.active=false;
tuio._alpha = 0;
var tuic = Scene.attachMovie("cursor","tuic"+i,120+i);
tuic.x=0;
tuic.y=0;
tuic.active=false;
tuic._alpha = 0;
objectList[i] = false;
cursorList[i] = false;
}
// create the cursor
function addCursor(sid, x, y){
var tuic = Scene["tuic"+sid];
tuic._alpha = 100;
Line.lineStyle(1,0x000000,100);
tuic._x=x;
tuic._y=y;
Line.moveTo(x,y);
}
// draws the movieclip on the scene
// In here it gets rotated and moved.
function updateObject(sid, id, x, y, a) {
//incoming += "set "+sid+" "+id+" "+x+" "+y+" "+a+"\n";
var tuio = Scene["tuio"+sid];
tuio._x=x;
tuio._y=y;
tuio.num.text = id;
tuio._rotation = a * 100;
tuio._alpha = 100;
}
// draws the cursor (fingers) on the scene.
// same as the object, moves as well.
function updateCursor(sid, x, y, a){
//incoming += "set "+sid+" "+id+" "+x+" "+y+" "+a+"\n";
var tuic = Scene["tuic"+sid];
if (tuic._x > 0){
tuic._x=x;
tuic._y=y;
Line.lineTo(x,y);
} else {
addCursor(sid, x, y);
}
}
// these two functions remove the movieclips
function removeObject(id) {
//incoming += "remove "+i+"\n";
var tuio = Scene["tuio"+id];
tuio.unloadMovie();
}
function removeCursor(id) {
//incoming += "remove "+i+"\n";
var tuic = Scene["tuic"+id];
tuic.unloadMovie();
Line.clear();
}
// Not used by this method, left in here for you, if you ever need it
//function draw(tuio) {
// tuio.clear();
// tuio.beginFill("0x000000",100);
//
// x1 = tuio.x-15;
// x2 = tuio.x+35;
// y1 = tuio.y-15;
// y2 = tuio.y+35;
// tuio.moveTo(x1,y1);
// tuio.lineTo(x2,y1);
// tuio.lineTo(x2,y2);
// tuio.lineTo(x1,y2);
// tuio.endFill();
//}
// attach the scroll manager movie
// (see its child movie's enterframe event for scroll code)
attachMovie("processScroll", "processScroll", 0);
// turn off ugly yellow highlight on buttons
_focusrect = false;
// *** create a new socket and attempts to connect to the server
function connect () {
mySocket = new XMLSocket();
mySocket.onConnect = handleConnect;
mySocket.onClose = handleClose;
mySocket.onXML = handleIncoming;
if (!mySocket.connect(IPaddress, port)) gotoAndStop("connectionFailed");
}
// *** disconnect from the server
function disconnect () {
for (var i=0;i<120;i++) {
//var tuio = Scene["tuio"+i];
var tuio = "tuio"+id
tuio.removeMovieClip();
}
mySocket.close();
mySocket.connected = false;
incoming = "";
gotoAndStop(2);
}
// *** event handler for incoming XML-encoded OSC packets
function handleIncoming (xmlIn) {
// USEFUL DEBUG - display the raw xml data in the output window
// incoming += xmlIn.toString() +"\n";
// parse out the packet information
e = xmlIn.firstChild;
if (e != null && e.nodeName == "OSCPACKET") {
packet = new OSCPacket(e.attributes.address, e.attributes.port,
e.attributes.time, xmlIn);
displayPacketHeaders(packet);
parseMessages(xmlIn);
}
// tell the text field manager it's time to scroll
incomingUpdated = true;
lastScrollPos = incoming.scroll;
}
// *** event handler to respond to successful connection attempt
function handleConnect (succeeded) {
if(succeeded) {
incoming += "Connected to " + IPaddress + " on port " + port + "\n";
mySocket.connected = true;
} else {
mySocket.connected = false;
}
gotoAndPlay("connecting");
}
function handleClose () {
incoming += ("The server at " + IPaddress + " has terminated the connection.\n");
incomingUpdated = true;
mySocket.connected = false;
numClients = 0;
}
function OSCPacket(address, port, time, xmlData) {
this.address = address;
this.port = port;
this.time = time;
this.xmlData = xmlData;
}
function displayPacketHeaders(packet) {
/*incoming += "** OSC Packet from " + packet.address +
", port " + packet.port +
" for time " + packet.time + "\n";
*/
}
// *** parse the messages from some XML-encoded OSC packet
//
// THIS IS WHERE YOU COULD DO SOMETHING COOL
// (probably based on the value of the arguments)
function parseMessages(node) {
//trace(node);
if (node.nodeName == "MESSAGE") {
if (node.attributes.NAME=="/tuio/2Dobj") {
// from here on it parses the object (fiducial markers) data
var child = node.firstChild;
var cmd = child.attributes.VALUE;
if (cmd=="set") {
child = child.nextSibling;
var sID = child.attributes.VALUE;
child = child.nextSibling;
var id = child.attributes.VALUE;
child = child.nextSibling;
var x = child.attributes.VALUE * 640;
child = child.nextSibling;
var y = child.attributes.VALUE * 480;
child = child.nextSibling;
var a = child.attributes.VALUE;
child = child.nextSibling;
var X = child.attributes.VALUE;
child = child.nextSibling;
var Y = child.attributes.VALUE;
child = child.nextSibling;
var A = child.attributes.VALUE;
child = child.nextSibling;
var m = child.attributes.VALUE;
child = child.nextSibling;
var r = child.attributes.VALUE;
var speed = Math.sqrt(X*X+Y*Y);
// sID, ID, xPos, yPos, angle, mSpeed, rSpeed, mAccel, rAccel
updateObject(sID,id,int(x),int(y),a);
// this is to check if the marker is still there
} else if (cmd=="alive") {
var newList = new Array(120);
for (var i=0;i<120;i++) { newList[i] = false; }
child=child.nextSibling;
while (child != null) {
var id = child.attributes.VALUE;
newList[id]=true;
child=child.nextSibling;
}
for (var i=0;i<120;i++) {
if ((objectList[i]==true) && (newList[i]==false)) {
removeObject(i);
}
}
objectList = newList;
}
} else if (node.attributes.NAME=="/tuio/2Dcur") {
// from here on it parses the cursor data
var child = node.firstChild;
var cmd = child.attributes.VALUE;
if (cmd=="set") {
child = child.nextSibling;
var sID = child.attributes.VALUE;
child = child.nextSibling;
var x = child.attributes.VALUE * 640;
child = child.nextSibling;
var y = child.attributes.VALUE * 480;
child = child.nextSibling;
var X = child.attributes.VALUE;
child = child.nextSibling;
var Y = child.attributes.VALUE;
child = child.nextSibling;
var m = child.attributes.VALUE;
