Zemen
YaBB Newbies
Offline
Posts: 17
Re: connect processing and flash
Reply #13 - May 17th , 2010, 9:17pm
use flosc can fix my problem!!!! but most of the examples are using AS1 or AS2, below is my AS3, hope it can help you guys:import flash.events.*; import flash.net.*; ///////////////////////////////////////////////////////////////////////////// //from here is connected to flosc var mySocket:XMLSocket; //mySocket.allowDomain("*"); // *** create a new socket and attempts to connect to the server function connect() { mySocket = new XMLSocket(); mySocket.addEventListener(Event.CONNECT, handleConnect); mySocket.addEventListener(Event.CLOSE, handleClose); mySocket.addEventListener(DataEvent.DATA, handleIncoming); mySocket.connect("172.21.129.18",3000); } function handleConnect(e:Event):void { trace("XML Socket connected!"); gotoAndStop(2); } function handleClose(e:Event):void { trace("XML Socket closed!"); } function handleIncoming(e:DataEvent):void { trace("Incoming:",e.data); a.writeDigitalPin(6, Arduino.HIGH); var XMLData:XMLList=new XMLList(e.data); //XMLData.MESSAGE.(@NAME=="thomas")); trace_txt.text=e.data; //trace(XMLData.MESSAGE.(@NAME=="thomas")); } // *** build and send XML-encoded OSC // //THIS IS ANOTHER PLACE TO DO SOMETHING COOL press_btn.addEventListener(MouseEvent.MOUSE_UP, mUp); function mUp(e:MouseEvent):void { sendOSC("Thomas", "Genius", "172.21.129.18", 2000); } function sendOSC(name:String, arg:String, destAddr:String, destPort:int):void { var xmlOut:XML = <OSCPACKET Address="" PORT="" TIME="0"> <MESSAGE NAME=""> <ARGUMENT TYPE="s" VALUE="" /> </MESSAGE> </OSCPACKET>; xmlOut.@ADDRESS=destAddr; xmlOut.@PORT=destPort; xmlOut.MESSAGE.@NAME=name; xmlOut.MESSAGE.ARGUMENT.@VALUE=arg; //trace("xmlout:",xmlOut); if (mySocket&&mySocket.connected) { mySocket.send(xmlOut.toString()); } } connect();