Home arrow Flash arrow Page 5 - Building Preloaders
FLASH

Building Preloaders


A preloader prevents a Flash movie from playing back until the movie can stream properly. Without a preloader, you may find that your movie tries to play frames that haven't been loaded yet, leading to unacceptable playback behavior. This article explains how to build a preloader. It is excerpted from chapter 20 of the Flash 8 Cookbook, written by Joey Lott (O'Reilly, 2006; ISBN: 0596102402). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 16
February 22, 2007
TABLE OF CONTENTS:
  1. · Building Preloaders
  2. · 20.1 Determining How a Movie Will Download
  3. · 20.2 Building a Simple Preloader
  4. · 20.3 Building a Preloader that Displays Load Percentage
  5. · 20.4 Using a Progress Bar to Create a Graphical Preloader
  6. · 20.5 Creating Preloaders for Files with Exported Symbols
  7. · 20.6 Creating Preloaders for Files with Components

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Building Preloaders - 20.4 Using a Progress Bar to Create a Graphical Preloader
(Page 5 of 7 )

Problem

You want to create a preloader that displays a progress bar indicating how much of the movie has loaded.

Solution

Modify the script from Recipe 20.2 to update the _xscale property of a movie clip.

Discussion

Although simply displaying a text-based progress indicator to the user (as in Recipe 20.3) may work for some applications, you’ll more frequently want to display the progress in some sort of visual, animated manner. The most common such indicator is the progress bar. The progress bar, as the name suggests, is a rectangular shape (the bar) that indicates the progress as the file downloads. Although you can
certainly make more elaborate sorts of indicators, the progress bar is the standard, and the basic principals in creating a basic progress bar apply to any progress indicator.

The script in Recipe 20.2 takes care of the majority of the work in creating any sort of basic preloader—graphical or not. So you’ll want to use the same script when adding a progress bar. However, you’ll want to then add just one line of code (shown in boldface):

  stop();
  var nPreloaderInterval:Number = setInterval(this, "checkPreloader", 100);

  function checkPreloader():Void {
  var nLoadedBytes:Number = this.getBytesLoaded();
  var nTotalBytes:Number = this.getBytesTotal();

  mProgressBar._xscale = nLoadedBytes / nTotalBytes * 100;
  if(nLoadedBytes >= nTotalBytes) {
   
clearInterval(nPreloaderInterval);
   
play();
 
}
  }

The new line of code tells Flash to adjust the scale in the x-direction for a movie clip calledmProgressBar such that it corresponds to the percentage of the file that has downloaded. Therefore, in order for the code to be effective, you must add a movie clip instance to the stage with an instance name ofmProgressBar. That movie clip ought to contain rectangular artwork that is left-aligned (meaning that the left edge of the rectangle shape is positioned at 0).


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials