Using Accelerometer for Flash Mobile Applications

This is tutorial on using the accelerometer for your Flash Mobile applications. This code was modified from an example that I came across from Adobe.

import flash.sensors.Accelerometer;

var my_acc:Accelerometer = new Accelerometer();

//my_txt.text = “Acc support is “+Accelerometer.isSupported;

my_acc.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate);
function onAccUpdate(e:AccelerometerEvent):void{
ball.x -= (e.accelerationX*10);
ball.y += (e.accelerationY*10);

if (ball.x stage.stageWidth) {
ball.x = stage.stageWidth;

if (ball.y stage.stageHeight)
{ ball.y = stage.stageHeight;


This is a simple application that has a ball moving in the direction that the phone is tilting. You can test the application by downloading it below.

Download Android Air Application

I am not liable to damage it may cause to your phone. Use at your own risk.

I tried it on my phone, so their should be no problem.