Flash
  Home arrow Flash arrow Page 4 - Building Preloaders
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Building Preloaders
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 16
    2007-02-22

    Table of Contents:
  • Building Preloaders
  • 20.1 Determining How a Movie Will Download
  • 20.2 Building a Simple Preloader
  • 20.3 Building a Preloader that Displays Load Percentage
  • 20.4 Using a Progress Bar to Create a Graphical Preloader
  • 20.5 Creating Preloaders for Files with Exported Symbols
  • 20.6 Creating Preloaders for Files with Components

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building Preloaders - 20.3 Building a Preloader that Displays Load Percentage


    (Page 4 of 7 )

    Problem

    You want to build a preloader that continually updates a display of the percent loaded.

    Solution

    Divide getBytesLoaded( ) by getBytesTotal( ), multiply the output by 100, and use a dynamic text field to display the output.

    Discussion

    The basic preloader script discussed in the previous recipe serves as the foundation for this preloader script. With the preceding script, nothing happens until the movie is fully downloaded, at which time the if statement checking load status evaluates to true, a play( ) action is executed, and the preloader movie clip is removed.

    In this variation of the script, I’ve added a line of code (shown in boldface) that outputs the percent that has loaded to a dynamic text field on the stage:

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

      function checkPreloader():Void {
        var nLoadedBytes:Number = this.getBytesLoaded();
        var nTotalBytes:Number = this.getBytesTotal();
        tProgress.text = Math.round(nLoadedBytes / nTotalBytes * 100) + "% downloaded";
       
    if(nLoadedBytes >= nTotalBytes) {
          clearInterval(nPreloaderInterval);
          play();
        }
      }

    In addition to adding the script, you need to add the dynamic text field to the stage in frame 1. Create a dynamic text field, and give it an instance name oftProgress.

    See Also

    Recipe 8.2, Recipe 20.2

    More Flash Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Flash 8 Cookbook," published by O'Reilly....
     

    Buy this book now. This article is excerpted from chapter 20 of the Flash 8 Cookbook, written by Joey Lott (O'Reilly, 2006; ISBN: 0596102402). Check it out today at your favorite bookstore. Buy this book now.

    FLASH ARTICLES

    - 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
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT