/ Published in: ActionScript 3
An easy way to detect shakes on mobile devices with equipped accelerometer.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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"); }
URL: http://blog.vamapaull.com/?p=671