Return to Snippet

Revision: 53543
at November 26, 2011 09:26 by vamapaull


Initial Code
var lastShake:Number = 0;
var shakeWait:Number = 500;

var acc:Accelerometer = new Accelerometer();
acc.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate);

function onAccUpdate(e:AccelerometerEvent):void
{
	if(getTimer() - lastShake > shakeWait && (e.accelerationX >= 1.5 || e.accelerationY >= 1.5 || e.accelerationZ >= 1.5))
	{
		shakeIt();
		lastShake = getTimer();
	}
}

function shakeIt()
{
	trace("device has been shaked");
}

Initial URL
http://blog.vamapaull.com/?p=671

Initial Description
An easy way to detect shakes on mobile devices with equipped accelerometer.

Initial Title
Device Shake – Accelerometer

Initial Tags
phone, actionscript, flash, 3

Initial Language
ActionScript 3