如果您正在寻找加速度计数据,则不需要 MOUSE_UP 和 MOUSE_DOWN。您需要 Accelerometer 类和相关事件。
尝试这样的事情:
import flash.sensors.Accelerometer;
import flash.events.AccelerometerEvent;
var accel:Accelerometer = new Accelerometer();
accel.addEventListener(AccelerometerEvent.UPDATE, handleAccelUpdate);
更新处理程序:
function handleAccelUpdate(e:AccelerometerEvent):void{
//inside this function you now have access to acceleration x/y/z data
trace("x: " + e.accelerationX);
trace("y: " + e.accelerationY);
trace("z: " + e.accelerationZ);
//using this you can move your MC in the correct direction
c_ball.x -= (e.accelerationX * 10); //using 10 as a speed multiplier, play around with this number for different rates of speed
c_ball.y += (e.accelerationY * 10); //same idea here but note the += instead of -=
//you can now check the x/y of your c_ball mc
if(c_ball.x == 100 && c_ball.y == 100){
trace("you win!"); //fires when c_ball is at 100, 100
}
}
现在这将让您“滚动”您的 MC 离开屏幕,因此您可能想要添加某种边界检查。
查看这篇精彩的文章以获取更多信息:
http://www.republicofcode.com/tutorials/flash/as3accelerometer/