Posted By

vamapaull on 11/26/11


Tagged

phone actionscript flash 3 as3 device accelerometer shakeAccelerometerEventshaking


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

letmein_xxi


Device Shake – Accelerometer


 / Published in: ActionScript 3
 

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

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

  1. var lastShake:Number = 0;
  2. var shakeWait:Number = 500;
  3.  
  4. var acc:Accelerometer = new Accelerometer();
  5. acc.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate);
  6.  
  7. function onAccUpdate(e:AccelerometerEvent):void
  8. {
  9. if(getTimer() - lastShake > shakeWait && (e.accelerationX >= 1.5 || e.accelerationY >= 1.5 || e.accelerationZ >= 1.5))
  10. {
  11. shakeIt();
  12. lastShake = getTimer();
  13. }
  14. }
  15.  
  16. function shakeIt()
  17. {
  18. trace("device has been shaked");
  19. }

Report this snippet  

You need to login to post a comment.