×
Namespaces

Variants
Actions

Archived:Create a moving ball using accelerometer with Kuneri Lite

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

We do not recommend Flash Lite development on current Nokia devices, and all Flash Lite articles on this wiki have been archived. Flash Lite has been removed from all Nokia Asha and recent Series 40 devices and has limited support on Symbian. Specific information for Nokia Belle is available in Flash Lite on Nokia Browser for Symbian. Specific information for OLD Series 40 and Symbian devices is available in the Flash Lite Developers Library.

Article Metadata
Article
Created: Felipe.Sampaio (24 Nov 2008)
Last edited: hamishwillee (14 May 2013)

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.

This page was last modified on 14 May 2013, at 04:43.
89 page views in the last 30 days.