1. Home
  2. Computing & Technology
  3. Animation

Flash Animation 13: Creating a Simple Preloader

By , About.com Guide

8 of 9

Breaking Down the Code

Now let's break the code down so it makes a bit more sense:

play() ;

This just tells the movie clip to play.

loaded = _root.getBytesLoaded() / _root.getBytesTotal * 100;

I know this looks complicated, but it's really not. What this does is define a variable called "loaded", which represents the percentage of the movie loaded.

It's really just a simple math string; _root.getBytesLoaded () is a universal variable that fetches the number of bytes of the document loaded, and _root.getBytesTotal is a universal variable that fetches the number of bytes of the document total. So in this string we're saying "Divide the number of bytes loaded by the number of bytes total, then multiply by 100 to give me the percentage loaded, which equals the variable "loaded"."

if(loaded != 100){

This is the start (and first half) of what's called an "if/else statement" that will perform one action based on certain results, or another action based on any other results, both defined by parameters. What an if/else statement says is, "If this condition is met, then do this. If there's anything else but this condition, then do this instead."

The condition for this statement is "loaded != 100". So it's saying that if "loaded" (the variable we defined as the percent of the movie loaded) doesn't equal 100 (that's what != stands for: it's like of like a notequal sign, as if the ! negates the meaning of the =), then a certain action should be performed.

Explore Animation
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Flash Animation 13: Creating a Simple Preloader

©2009 About.com, a part of The New York Times Company.

All rights reserved.