ActionScript & Flash

Preload an ActionScript game

A preloader should tell the player what is happening while required assets arrive. The difficult part is keeping the preloader small enough to appear before the game’s large classes and images. If all assets are pulled into the first frame, a progress bar may show up only after most loading has finished.

Keep the loading screen independent of game initialization. Monitor bytesLoaded and bytesTotal, guard against a zero total and move into the game only after the loading and initialization phases both succeed.

Loading errors need a readable message and a retry path. A progress value that reaches 100 percent is not evidence that image decoding, scene construction or audio setup has completed.

Try the idea

var total:Number = loaderInfo.bytesTotal;
var ratio:Number = total > 0 ? loaderInfo.bytesLoaded / total : 0;
progress.scaleX = ratio;
if (total > 0 && ratio >= 1 && !started) {
  started = true; initializeGame();
}