Q:

OpenFL take input from device gyroscope

Okay, so I am working on a mobile app in OpenFL and Haxe. I would like to gather input from the gyroscope, or more specifically about the orientation of the phone. I have searched the openfl docs, and google for some kind of documentation or examples on this sort of thing. I had no luck there and would like to know if anyone could point me toward some.

A:

Make a new Accelerometer:
private var _acc:Accelerometer = new Accelerometer();

Add an event listener to it:
_acc.addEventListener(AccelerometerEvent.UPDATE, updateAcc);

Listen to results:
private function updateAcc(Event:AccelerometerEvent):Void 
{
    trace("x:" + Event.accelerationX);
    trace("y:" + Event.accelerationY);
    trace("z:" + Event.accelerationZ);
}

Note than iOS accelerometer values are inverted.

