Sending OSC
Besides receiving Tuio tracking data the tuio-as3 library is also capable of sending osc messages. This could be very interesting for osc based communication between several flash movies or if you want to flash as a ui framwork only and e.g. sound synthesis is done by a another program which receives commands from the flash movie via osc.
To send osc messages you have to create an OSCManager.
-
import org.tuio.osc.*;
-
-
var oscManager:OSCManager = new OSCManager(null, new UDPConnector("127.0.0.1", 3333, false));
The first attribute is null because this is where normally the incoming connector would go but we won't need one now.
Next we have to create our OSCMessages and send them via the OSCManager.
-
var myMsg:OSCMessage = new OSCMessage();
-
myMsg.address = "/my/msg/target";
-
myMsg.addArgument("s", "Hello World");
-
-
oscManager.sendOSCPacket(myMsg);
This will send a message containing a string "Hello World" to the OSC address "/my/msg/target". Currently the following datatypes are supported:
- s A string
- i An integer
- f A float
- b A blob / ByteArray
- t An OSCTimetag
- d A double
- c An ascii character
- r A RGBA color
- T A boolean true. You don't have to specify a value for this type.
- F A boolean false. You don't have to specify a value for this type.
- N A null value. You don't have to specify a value for this type.
- I Infinity. You don't have to specify a value for this type.
You can also add onedimensional OSC arrays to an OSCMessage like this:
-
myMsg.addArguments("i[ssi]", [123, "Hello World", "Oh hai", 123]);
You can also wrap multiple OSCMessages into an OSCBundle like this:
-
var myBundle:OSCBundle = new OSCBundle();
-
myBundle.addPacket(myMsg);
-
myBundle.addPacket(myMsg2);
-
[...]
-
-
oscManager.sendOSCPacket(myBundle);
You should be able now to send osc instructions to any kind of OSC devices via UDP. If you happen to run into any problems write a comment or send me a mail.