开发者

Android hardware and Adobe AIR cont

开发者 https://www.devze.com 2023-02-08 20:45 出处:网络
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 applicati

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

精彩评论

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

关注公众号