We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing & Flash
Page Index Toggle Pages: 1
Processing & Flash (Read 16823 times)
Processing & Flash
May 7th, 2005, 2:43am
 
So


my big question is


can this cool stuff go in flash



somehow




let the games begin
Re: Processing & Flash
Reply #1 - May 7th, 2005, 3:16am
 
well, there is saveFrame() and the freshly revived AIExport library ...

http://processing.org/reference/saveFrame_.html

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=os_libraries_tools;action=display;num=1114686460;start=1

... or you could talk to flash in many ways. for example:

http://processing.org/reference/libraries/net/index.html

hope this get's you started.

F
Re: Processing & Flash
Reply #2 - May 7th, 2005, 3:19am
 
found more:

http://incubator.quasimondo.com/processing/flash_processing_communication_1.php

and there have been some questions about flash in the alpha forum, try a search there ...

F
Re: Processing & Flash
Reply #3 - Nov 30th, 2005, 8:20am
 
Obviously it was some time ago that this thread was originally posted and discussed, but I figured it couldn't hurt to put in some documentation on how Processing -> Flash can work.

The best and simplest way I have found is to create a server in Processing, and have it send the variables to Flash, which it then recieves using an XML socket object.

here is some example code using a comma as a delimiter (divides the variables being sent in the same stream)

Processing:

Code:

import processing.net.*;

int port = 9001;
Server myServer;
//variables for sending
byte zero = 0;
int total = 1;
int total2 = 2;

void setup(){
size(200, 200);
myServer = new Server(this,port);
}

void draw(){
myServer.write(total+","+total2);
//the trick is this next line that sends the "0" termination byte unaltered and alone, this way it doesn't get evaluated with the other variables being sent
myServer.write(zero);
//"zero" is the termination byte, which Flash's XMLSocket uses to figure out when a transmission stream has ended. This also means that any variables that are being sent as zero bytes need to be shifted (say +1, for example) and evaluated in Flash accordingly, or else Flash will kill the transmission there
}


Flash:

Code:

//establish connection to get data
serialServer = new XMLSocket();
serialServer.connect("127.0.0.1",9001);
serialServer.onConnect = function(success){
trace("the client connected to the server");
}
serialServer.onClose = function(){
trace("the client disconnected :(");
}
serialServer.onData = gotSomething;
//what to do with data
function gotSomething(datar){
parts = datar.split(",");
//here the comma is treated as the separation between variables. Anything (except for a zero byte) can be used, so long as the code in processing is changed as well
speech = parts[0];
speech2 = parts[1];
}


Hooray! Hopefully this will be of some help.
Re: Processing & Flash
Reply #4 - Jun 8th, 2006, 12:34am
 
You are the man!
I am using your code to indirectly send MIDI into flash using processing's MIDI library!
How cool...
Re: Processing & Flash
Reply #5 - Mar 14th, 2007, 5:20pm
 
Has anyone tried this recently? I had this working a year or two back for a project, but now i need it for another, and Flash 8 connects, but the XMLSocket/onData and XMLSocket.onXML event handlers don't seem to receive anything - even using the code listed below
Re: Processing & Flash
Reply #6 - Mar 14th, 2007, 5:26pm
 
I'm considering this:

http://www.benchun.net/flosc/

OSC has served me well in the past. Not sure if it will be smooth and quick though.
Re: Processing & Flash
Reply #7 - Mar 14th, 2007, 5:46pm
 
thanks for the answer - i managed to get the XMLSocket to receive stuff in the end.

My main concern with using the Processing Server object is that if a client disconnects, the whole Processing applet falls over. I'll probably write something a bit more robust in Java instead, maybe integrate it in the processing application.

i've used OSC - with MaxMSP & Flash - a fair while ago - worked fine, no hiccups in a performance using it. MaxMSP moved on though and got it's own networking stuff - not checked that out yet properly.
Re: Processing & Flash
Reply #8 - Aug 20th, 2007, 1:31am
 
Is it possible to embed processing in flash somehow? I'm trying to create an application using processing for the visualisations and flash for the User Interaction without a web browser or Javascript. Any suggestions?
Re: Processing & Flash
Reply #9 - Jul 1st, 2008, 2:10am
 
Hi, i have a problem to make a caroussel menu icons spin with processing,processing conect and sent data,but i dont know the changes to make the camera act as a mouse,to spin the around the carousel,heres´s the code

<--------------PROCESSING------------------------->

import processing.net.*;

int port = 9001;
Server myServer;
byte zero = 0;
int total = 7;
int total2 = 2;
import JMyron.*;

JMyron m;//a camera object

void setup(){
 size(320,240);
 m = new JMyron();//make a new instance of the object
 m.start(width,height);//start a capture at 320x240
 m.trackColor(0,0,200,200);//R, G, B, and range of similarity
 m.minDensity(100); //minimum pixels in the glob required to result in a box
 println("Myron " + m.version());
 noFill();
 myServer = new Server(this,port);
}

void draw(){
 m.update();//update the camera view
 drawCamera();//draw the camera to the screen
 int[][] b = m.globBoxes();//get the center points
 int xi=1000, yi=1000, xf=0, yf=0;
 int xc, yc;  

 //draw the boxes
 stroke(255,0,0);
 for(int i=0;i<b.length;i++){
   if(b[i][0]<xi)
     xi = b[i][0];
   if(b[i][1]<yi)
     yi = b[i][1];

   if(b[i][0]+b[i][2]>xf)
     xf = b[i][0]+b[i][2];

   if(b[i][1]+b[i][3]>yf)
     yf = b[i][1]+b[i][3];

  // rect( b[i][0] , b[i][1] , b[i][2] , b[i][3]);
 }
if(b.length > 0)
{   rect( xi , yi , xf-xi , yf-yi);

 xc = xi + ( xf-xi)/2;
 yc = yi + ( yf-yi)/2;
 myServer.write( xc +","+ yc);
 myServer.write(zero);
 }
 
}

void drawCamera(){
 int[] img = m.image(); //get the normal image of the camera
 loadPixels();
 for(int i=0;i<width*height;i++){ //loop through all the pixels
   pixels[i] = img[i]; //draw each pixel to the screen
 }
 updatePixels();

}

void mousePressed(){
 m.settings();//click the window to get the settings
}

public void stop(){
 m.stop();//stop the object
 super.stop();
}


<-----------------------FLASH CODE---------------------->
<code>
function mover()
{
//(WHERE I GIVE THE ATTRIBUTES FOR PROCESSING??)

this._x = Math.cos(this.angle) * radiusX + centerX;  

this._y = Math.sin(this.angle) * radiusY +  centerY;

var s = (this._y - perspective) /(centerY+radiusY-perspective);

this._xscale = this._yscale = s*100;

this.angle += this._parent.speed;

this.swapDepths(Math.round(this._xscale) + 100);
}

this.onMouseMove = function()
{

speed = (this._xmouse-centerX)/2500;
}
</code>
I hope somebody give me a hand,i have read all sections and topics and didn´t find(or not see) a solution...just need to
know how to give the attributes ( processins vars)to a camera be my mouse!
Thank you
Regards

Re: Processing & Flash
Reply #10 - Jul 23rd, 2008, 6:41pm
 
NerdUprising wrote on Nov 30th, 2005, 8:20am:
Obviously it was some time ago that this thread was originally posted and discussed, but I figured it couldn't hurt to put in some documentation on how Processing -> Flash can work.

The best and simplest way I have found is to create a server in Processing, and have it send the variables to Flash, which it then recieves using an XML socket object.

here is some example code using a comma as a delimiter (divides the variables being sent in the same stream)

Processing:

Code:

import processing.net.*;

int port = 9001;
Server myServer;
//variables for sending
byte zero = 0;
int total = 1;
int total2 = 2;

void setup(){
size(200, 200);
myServer = new Server(this,port);
}

void draw(){
myServer.write(total+","+total2);
//the trick is this next line that sends the "0" termination byte unaltered and alone, this way it doesn't get evaluated with the other variables being sent
myServer.write(zero);
//"zero" is the termination byte, which Flash's XMLSocket uses to figure out when a transmission stream has ended. This also means that any variables that are being sent as zero bytes need to be shifted (say +1, for example) and evaluated in Flash accordingly, or else Flash will kill the transmission there
}


Flash:

Code:

//establish connection to get data
serialServer = new XMLSocket();
serialServer.connect("127.0.0.1",9001);
serialServer.onConnect = function(success){
trace("the client connected to the server");
}
serialServer.onClose = function(){
trace("the client disconnected :(");
}
serialServer.onData = gotSomething;
//what to do with data
function gotSomething(datar){
parts = datar.split(",");
//here the comma is treated as the separation between variables. Anything (except for a zero byte) can be used, so long as the code in processing is changed as well
speech = parts[0];
speech2 = parts[1];
}


Hooray! Hopefully this will be of some help.


This was extremely helpful! Thank you Smiley
Re: Processing & Flash
Reply #11 - Oct 30th, 2008, 10:36am
 
Hi guys,

Nice post.
Any way i can talk from Flash back to the Java (processing) server ?
Re: Processing & Flash
Reply #12 - Nov 4th, 2008, 4:25pm
 
you can send xml objects to processing (java) using the 'send' method of your xml socket object.

example:

var xml = new XML();
var pos = xml.cerateElement('position');
pos.attributes.x = 100;
pos.attributes.y = 100;
xml.appendChild(pos);

xmlSocket.send(xml);

for more performance i would rather use the binary socket of action script 3 than the xml socket.

greets
Re: Processing & Flash
Reply #13 - Jan 14th, 2010, 9:53am
 
Hi, I was reading about this matter and i used the code from fadore and yes the connection its ok, the output in flash said "the client connected to the server"  but dont send any data??? Undecided somebody know how do it?
Page Index Toggle Pages: 1