Ever wanted to build super cool Games/Applications/Demos on your MacBook using Accelerometer ?
Yes, it is now possible to build all these cool stuff with Air 2.0 & MacBook.
MacBooks have a device called SMS ( Sudden Motion Sensor ) which can act as our Accelerometer. And using Air 2.0′s NativeProcess, we can invoke a native program to give us the Accelerometer data. Here is how the flow goes:
I got a simple C-Program called “motion” (bundled in the below package) which can give me X,Y & Z co-ordinates of Accelerometer & print on the console. I execute the process using NativeProcess API & capture the console output.
I made a wrapper class called “MBAcceleromoter” to make this entire process easier.
Click here to download the source & demo. ( Air 2.0 SDK required )
Click here to download Demo alone. ( Air 2.0 runtime required )
This package contains:
1. “motion” program to capture Accelerometer data
2. “MBAccelerometer” class to invoke & “motion” program & returned structured output through event dispatch mechanism.
3. Sample application (Accelerometer.mxml) built using APE
What are you waiting for ? Go ahead & create some amazing stuff.
Here is what I have built in this demo:









Shouldn’t you be able to do something like this?
import flash.sensors.Accelerometer;
var acc = new Accelerometer();
acc.addEventListener(‘update’, trace);
Any idea what the minimum requirements are for native Accelerometer support? It doesn’t seem to work on my Vista tablet.
You are right. That is the case for devices which have accelerometer support. But, Macbook does not have Accelerometer in it. That is why this post uses a round about way of using “Sudden Motion Sensors (SMS)” as Accelerometer. If the device actually had a Accelerometer, you could directly use the new inbuilt Accelerometer APIs provided by Air 2.0.
Device with Accelerometer & Air 2.0 are the only two requirements for using inbuilt Accelerometer APIs. But, you need to have a MacBook & Mac OS running Air 2.0 for the current SMS based example to work.