You Are Here:

Community: Wiki

This page was last modified on 21 September 2009, at 14:02.

How to make a battery indicator

From Forum Nokia Wiki

Reviewer Approved   

Compatibility: Flash Lite: 1.1, 2.x

Contents

Creating the battery indicator

  • Create a new movie clip
  • In this movie clip create at least 2 layers:
    • ActionScript: In this layer create as many keyframes as levels you want to display. (we will choose 8 levels in this example)
    • Level: In the first frame, create a level bar corresponding to the lowest level.
      In last frame create a keyframe and stretch your level bar to the highest level.
      Then add a motion tween.
    • Background: You can add a layer to put all your static components.
    • Your timeline will be like this: Image:Timeline_battery.jpg
  • In the first keyframe of the ActionScript layer add this code:
levelsNumber=8;
batMax = fscommand2("GetMaxBatteryLevel");
batLevel = fscommand2("GetBatteryLevel");
batSource = fscommand2("GetPowerSource");
batLevel2 = Math.ceil(batLevel*levelsNumber/batMax);
 
if (batSource == 0) { //If charger is not plugged
gotoAndPlay(batLevel2);
}
/* If charger is plugged, it will go to nextframe,
so the battery indicator will be animated.*/
  • In all other keyframes add this code:
call(1);
  • Put this movie clip into your scene.


Adding a percentage indicator

If you want to add a text indicator:

  • Create a new layer and add a dynamic text.
  • Fill the var field to link it to a variable (assuming batText in this example)
  • Add this code in the first keyframe of the ActionScript layer, just before the if statement:
batText = "Battery Level: " add math.ceil(batLevel*100/batMax) add "%";

Flash Lite 2.x recommended improvements

  • call(1): This action was deprecated in favor of the function statement.
  • [...]Level: " add Math.c[...]: Macromedia recommends that you use the + operator.


Download

You can download an example with source code here:
Battery Indicator 240*320 (swf + fla)
Image:Example_battery.jpg

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: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fImgBoE78E5fcomponentE5fforE5fFlashE5fE4citeX 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: qfnZuserE5FratingQNx5E2E0000X
RDF Facets: qfnZuserE5FtagQSxbatteryE20indicatorX