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 to Flash(AS3)
Page Index Toggle Pages: 1
Processing to Flash(AS3) (Read 1755 times)
Processing to Flash(AS3)
Jan 30th, 2009, 4:14pm
 
Just found an old post about Processing talking to Flash in actionscript 2, been working on an actionscript 3 version. I'm pretty new to using Processing but I thought I would share with you what I have. It's working for me hopefully it can help some of you. I had a look for another post similar but had no luck. So here is the code.

Processing Code
Code:
import processing.net.*;

int port = 9001;
Server myServer;
//Variables for Sending
byte zero = 0;
int total = 299;
int total2 = 200;

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

void draw () {
total += 1;
total2 +=2;
myServer.write(total+","+total2);
myServer.write(zero);
}



Actionscript 3
Code:
package {

import flash.display.Sprite;

import flash.events.Event;

import flash.events.DataEvent;

import flash.events.IOErrorEvent;

import flash.net.XMLSocket;


public class serverCom extends Sprite {




public var serialServer:XMLSocket;




public function serverCom() {



init();


}


public function init():void {



serialServer=new XMLSocket ;



serialServer.connect("127.0.0.1",9001);




serialServer.addEventListener(DataEvent.DATA,onReceiveData);




serialServer.addEventListener(Event.CONNECT,onServer);



serialServer.addEventListener(Event.CLOSE,onServer);



serialServer.addEventListener(IOErrorEvent.IO_ERROR,onServer);


}


// --== EVENTS ==-- \\


public function onServer(event:Event):void {



trace(event);


}


public function onReceiveData(dataEvent:DataEvent):void {




var Data:DataEvent=dataEvent;



//trace(Data);





// This grabs the data from Data var which is the string passed



// from our processing server.



var test=Data.data;



//trace(test);






// This splits the variables we are passing.



var parts:Array=test.split(",");



trace("parts0 this is the first variable: " + parts[0]);



trace("parts1 this is the second variable: " + parts[1]);


}

}
}


Good Luck
Happy Coding =D
Re: Processing to Flash(AS3)
Reply #1 - Feb 27th, 2009, 9:21pm
 
Thanks for sharing!
Page Index Toggle Pages: 1