You Are Here:

Community: Wiki

This page was last modified on 26 November 2008, at 18:31.

Create a moving ball using accelerometer with Kuneri Lite

From Forum Nokia Wiki


Hi all,

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

Image: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.

Download

 .sis
 .fla

More

See more at Flash Lite Effort

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5fmakeE5faE5fsignalE5findicatorX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZflashQ qfnZtopicQUqfnTopicZflashE5fliteQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx4E2E0000X