MakingThings just released a bunch of software updates involved with Flash and the Make Controller that nullifies a lot of my previous work with AS3 and flosc. While some of the components still seem a bit buggy, they represent some major improvements. The best news to come out of this round of releases is that the flosc socket server can now be ditched (sorry, Ben Chun) in favor of connecting to the Make Controller using a new version of mchelper. Additionally it is now possible, from Flash, to connect to a board using either USB or Ethernet. As a result, I'm starting my series over to take these latest developments into account. To get stared, grab the latest versions of the following files from MakingThings:
- mchelper 2.0
- heavy 1.2 rc4
- New AS3 classes
Step 1: Erase the Current Firmware To do this, connect power to the board and use a jumper on the 2 pins marked "ERASE" near the JTAG connector on the board. This will erase everything on the board including the firmware. Turn off the power, remove the jumper, then reconnect the power to restart the board. This will put the board into receive mode.
Step 2: Upload heavy 1.2 rc4 There seems to be a bug in mchelper 2.0 in that the option to upload firmware to the Make Controller is always grayed-out. So you'll need to use a previous version in order to install the new heavy 1.2 rc4 firmware. To do this, fire up mchelper 1.2 then simply select the .bin file and click upload. Restart the board after the firmware has updated.
Step 3: Connecting to Flash Close mchelper 1.2 and open up mchelper 2.0. Send a test message to the board to make sure that everything is setup properly.
mchelper 2.0 now has an XML socket server built into it (unfortunately not a binary socket server), so rather than connecting to flosc as we did in the past, we connect to mchelper. This is straightforward enough:
var mcfConnection:McFlashConnect = new McFlashConnect();
From there, it's just a matter of setting up a bunch of event listeners, which isn't all that different from my previous examples:
One of the primary differences between the new MakingThings AS3 classes and the others that I've written about is the addition of some methods to not only connect to mchelper (previously flosc), but also to determine when a controller board is actually connected. This is a significant improvement, as then you can be sure that you're actually connected to the board. Additionally, the way the new classes are written opens up the possibility of connecting multiple boards, as they can be addressed individually by IP address, USB address, name (i.e.
/system/name) or serial number, which is a super cool feature.
Once the connection to mchelper is established and a board is detected, sending and receiving OSC packets is rather straightforward. Here's an example of how to send an OSC packet:
A really cool feature of mchelper 2.0 is that OSC packets that are being sent and received from Flash are traced out to the dialog window in mchelper, which helps tremendously with debugging. After compiling a SWF that sends an OSC packet containing
/system/name you should see the following in mchelper:
XML server --- New XML Connection
XML server --- /system/name
USB --- /system/name Make Controller Kit
That's really all there is to it. Thankfully, the new MakingThings code is much less unwieldy and ditches flosc, so kudos to them for making much-needed improvements.
Step 4: Conclusion - Let the Hacking Begin
I haven't had a chance to look at the new AS3 classes in great detail, but there are some nice new features. However, one thing that I noticed that was a bit disappointing was that all of the XML parsing is being done using
XMLDocument objects, which have been deprecated in AS3. There's no reason why this shouldn't be using Flash Player 9's native E4X capabilities, so that'll be one of the first things that I rewrite, being as how I already did that in the MakingThings AS2 classes that I ported to AS3 a while back.