I totally missed this but tinker.it in London had an Arduino + Flash workshop some weeks ago where they used as3Glue.
Besides from being used by tinker.it, as3Glue has been used to teach physical computing and prototyping at Stanford and at least one commercial project (the Spelar roll exhibition by Doberman). So far I’ve had around one thousand downloads of the code, and since I’ve received no bug reports since the last update it looks like it is working pretty well. Glue is the first library I’ve released as open source so I’m really happy about this…
I have just committed an alpha version of as3Glue to Google Code. as3Glue is an open source physical interaction libary for ActionScript 3. It enables communication between ActionScript 3 applications and Arduino boards. It can be used to monitor sensors such as rotary encoders and motion detectors, control actuators such as LEDs and motors, and to interface other electronics such as RFID readers from within Flash / Flex and Air applications.
Check it out here: as3Glue
August 16, 2007 | code, flash
Code optimization might seem daunting but you can get pretty far with a few tweaks. I recently ported a Java physics engine to ActionScript 3, the first results were rather depressive. When rendering a particle system with one hundred particles connected by 180 springs the frame rate dropped from 45 frames per second to about 15. By tuning the code I managed to get it back up to 40 fps which is pretty ok. More than twice as fast as the original code… The thing here is that I didn’t have to change anything fundamentally, I only had to tune the existing code a bit.
Some of these “tweaks” might not be so obvious so I though I’d share them. I won’t explain why these practices improves performance in AS3 (and AS2) as there are plenty of in depth discussions on other blogs. Take my word on it, google it or test it your self. Don’t overdo the optimization though. Sometimes it’s better to have well structured and clean code than optimized code and sometimes optimization just isn’t worth the trouble (more on this here). In general you should consider optimizations like these when you have code that is executed on every new frame or code with a lot of loops and/or iterations…
Practices for faster code:
- Do not use Array.length in loops
- Avoid array lookups.
- Access variables directly without using getter and setter functions.
- Use int for counters and array lookups.
- Use multiplication instead of division.
- And (this should go without saying) always declare the types of all variables…
Here are two implementations of the same loop:
//Slow loop:
for(var i = 0; i < particles.length; i++){;
if(particles[i].isFree()){
particles[i].getX() = vectors[i].getX()/2;
particles[i].getY() = vectors[i].getY()/2;
particles[i].getZ() = vectors[i].getZ()/2;
}
}
//Fast loop:
var np:int = particles.length, i:int=0;
for(i = 0; i < np; i++){
p = particles[i];
v = vectors[i];
if(p._free){
p._x = v._x*0.5;
p._y = v._y*0.5;
p._z = v._z*0.5;
}
}
Note: Variables are usually prefixed with underscores to indicate that they are private. I generally leave the underscores on variables which should be private and accessed through getters/setters but are made public for optimization reasons…
I’ve updated Arduino For Flash with Flash and Arduino code for the Parallax RFID reader and the Arduino Code for the Parallax RFID Reader with a new example that uses SoftwareSerial for RFID->Arduino communication. Enjoy…
I’ve just released Arduino for Flash, an ActionScript 3.0 package that makes it easy to control Arduino boards with the Firmata 1.0 firmware from Flash.