2011年4月8日星期五

BluetoothSender (or yet another Native Process post) « bioRex21's blog


Bluetooth communication in Flash is not possible natively (yet), so using Java (with Bluecove library) you can achieve this by using Native Process in AIR.

It works like this: FlashApp < — > AIRApp< — > Java. Of course, the AIRApp needs to be working on the background, and the FlashApp will be you main application (or it can be another AIR application).

I created an API to let Flash send commands to bluetooth, by the way it uses AS3 Signals for events dispatching. This is a code sample for searching devices:

If the image looks a but blurry, then you need glasses, nah just kidding, i actually looks like that

"Yeah that's cool, but how do I set everything up to create my app?" ok here it goes:

The first thing you need to do is to install BluecoveAIR   When you run it for the first time, select the path to javaw.exe by clicking the "Hey! Select Javaw.exe" button, the location is stored (via SharedObject) so you don't have to set that again.   A window will aid you to navigate to choose the exe file.   Once it's done you can see the "hello, Java stared" text (and a blue light indicator) that confirms that Java is good and ready to go.

That's pretty everything you need to do in order to start using API. You can notice some options for Local Connection, these are default settings, if you wanna change them, type the new connection names in the input fields, but also remember to change them in the FlashBluetooth constructor in your Flash app.

constructor params Local Connection default settings in the constructor (you may want to click the image).

没有评论:

发表评论