开发者

Android hardware and Adobe AIR cont

I asked in a previous post if it was possible to access native API from AIR. LadaRaider answered that it was not, but linked me to a site with a hack around it. Today I noticed a default AIR application in Flash that uses the accelerometer on an Android device to move a ball arou开发者_如何学JAVAnd. Can anyone explain this?

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;
    }
}

Where is this AccelerometerEvent.UPDATE coming from?

Thanks,


flash.sensors package.


Here is an example tutorial for accelerometer in AS3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜