Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:How to make a battery indicator in Flash Lite

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

This article shows how to create a battering indicator for a Flash Lite application.

Article Metadata
Code ExampleCompatibility
Platform(s): Flash Lite: 1.1, 2.x
Created: soueldi (28 May 2007)
Reviewed: Larry101 (21 Sep 2009)
Last edited: hamishwillee (14 May 2013)

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: Timeline battery.jpg
  • In the first keyframe of the ActionScript layer add this code:
batMax = fscommand2("GetMaxBatteryLevel");
batLevel = fscommand2("GetBatteryLevel");
batSource = fscommand2("GetPowerSource");
batLevel2 = Math.ceil(batLevel*levelsNumber/batMax);
if (batSource == 0) { //If charger is not plugged
/* If charger is plugged, it will go to nextframe,
so the battery indicator will be animated.*/
  • In all other keyframes add this code:
  • 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

  • {{Icode|call(1): This action was deprecated in favor of the function statement.
  • [...]Level: " add Math.c[...]: Macromedia recommends that you use the + operator.
This page was last modified on 14 May 2013, at 00:52.
57 page views in the last 30 days.