0

我正在测试加速度计,并尝试使用默认的 AIR for Android 示例,现在尝试在 Flash 中制作我自己的游戏。我复制了示例的代码:

    import flash.events.Event;

var accelX:Number;
var accelY:Number;

var fl_Accelerometer:Accelerometer = new Accelerometer();
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
    accelX = event.accelerationX;
    accelY = event.accelerationY;
}

ball.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(evt:Event){
    ball.x -= accelX*30;
    ball.y += accelY*30;

    if(ball.x > (480-ball.width/2)){
        ball.x = 480-ball.width/2;
    }
    if(ball.x < (0+ball.width/2)){
        ball.x = 0+ball.width/2;
    }
    if(ball.y > (800-ball.width/2)){
       ball.y = 800-ball.width/2;
    }
    if(ball.y < (0+ball.width/2)){
        ball.y = 0+ball.width/2;
    }

我不断收到此错误:

Scene 1, Layer 'actions', Frame 1, Line 6   1046: Type was not found or was not a compile-time constant: Accelerometer.
Scene 1, Layer 'actions', Frame 1, Line 6   1180: Call to a possibly undefined method Accelerometer.

我知道我犯了一个巨大的新手错误,但我非常感谢一些帮助,感谢您花时间阅读本文。

4

2 回答 2

1

您需要导入 Accelerometer 类:import flash.sensors.Accelerometer. 请务必发布为 Android Air 项目!

于 2012-11-05T02:53:56.207 回答
1

这也许可以帮助你:) http://www.flashandmath.com/mobile/anglemeasure/

于 2012-11-05T02:58:25.863 回答