×
Namespaces

Variants
Actions
Revision as of 08:58, 3 October 2012 by hamishwillee (Talk | contribs)

Archived:Create a moving ball using accelerometer with Kuneri Lite

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: Felipe.Sampaio (24 Nov 2008)
Last edited: hamishwillee (03 Oct 2012)

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’.

Bolinha.jpg

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.

54 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×