Create a moving ball using accelerometer with Kuneri Lite
In this post we’ll see how to use accelerometer in Flash Lite with Kuneri Lite. We’ll do a small example of the moving ball application, however simpler than the original application.
First of all, you have to create two layers, with names ‘content’ and ‘actions’. After this, create a movieclip with a circle like the showed below. Put the movieclip in the Stage with an instance name ‘ball_mc’.
After this, put the below code in the first frame of the ‘actions’ layer.
//Set fullScreen
fscommand2("FullScreen", true);
var lv:LoadVars = new LoadVars();
var X, Y, acelX, acelY, posX, posY;
//Reset the kuneri Lite variables.
klXAxis = 0;
klYAxis = 0;
lv.onLoad = function(success:Boolean){
if(success)
if(lv.klError == 0){
//Read the position.
lv.load("http://127.0.0.1:1001/Basic/accelerometer
?klCommand=readsensor");
X = lv.klXAxis;
Y = lv.klYAxis;
}
}
onEnterFrame = function():Void{
//Calculate the respective constant acceleration.
if(X > 0)
acelX = -1;
else acelX = 1;
if(Y > 0)
acelY = -1;
else acelY = 1;
posX = Math.abs(X/10) * acelX;
posY = Math.abs(Y/10) * acelY;
moveBall(posX, posY);
//Verify the limits of screen.
verifyPosition(ball_mc._x, ball_mc._y);
}
function verifyPosition(posX:Number, posY:Number):Void{
if(posY <= 10)
ball_mc._y = 10;
if(posY >= 310)
ball_mc._y = 310;
if(posX <= 10)
ball_mc._x = 10;
if(posX >= 230)
ball_mc._x = 230;
}
function moveBall(posX:Number, posY:Number):Void{
ball_mc._x += posX;
ball_mc._y += posY;
}
//Start the accelerometer, before first read.
lv.load("http://127.0.0.1:1001/Basic/accelerometer?klCommand=startsensor");
stop();
In this example the acceleration is constant, because this is a simple example for to create a moving ball with Flash Lite using KuneriLite accelerometer plugin by Flash Lite.



As FlashLite do not provide the access to system resources for S60 3rd edition devices, the Kuneri-Lite is used to bridge the gap.
The article demonstrates the use of this KuneriLite to access the devices native accelerometer. The article is recommended to try the implementation of KuneriLite and the accelerometer.