Flash
  Home arrow Flash arrow Page 3 - 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.2 Building a Simple Preloader


    (Page 3 of 7 )

    Problem

    You want to create a basic preloader, which will ensure smooth playback of a movie.

    Solution

    Attach a preloader script to the first frame of the movie.

    Discussion

    To add a simple preloader to any movie, attach the following script to the first frame of the timeline:

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

      function checkPreloader():Void {
       
    var nLoadedBytes:Number = this.getBytesLoaded();
       
    var nTotalBytes:Number = this.getBytesTotal();
       
    if(nLoadedBytes >= nTotalBytes) {
         
    clearInterval(nPreloaderInterval);
       
    play();
       
    }
      }

    This script stops the playhead in the first frame, preventing further playback, until the preloader has verified that the entire SWF has loaded. It then uses an interval function to poll the SWF for the download progress every 100 milliseconds or so. When the number of downloaded bytes equals the total number of bytes, it knows that the file has downloaded entirely. At that point, it stops the interval and plays the timeline.

    From a functional standpoint, this script accomplishes what it sets out to: it guarantees the smooth playback of the movie. However, it communicates none of this to the user. That is, while the script is busy determining whether the movie has fully loaded, the user sees only the content on frame 1. At a minimum, you should also put a message in frame 1 that indicates that the movie is loading and will begin playback when it has loaded. Users will have no way of knowing how long they will have to wait, but at least they won’t initially assume the movie is broken. Place the contents of the main movie beginning on frame 2 or another frame, which you can specify by substituting a gotoAndPlay( ) action in place of the play( ) action.

    To test the functionality of the preloader, add it to a Flash document with a large bitmap, sound, or other asset on frame 2 or later and test the movie (Control -> Test Movie). Be sure to choose View -> Show Streaming for the full effect.

    See Also

    Recipe 20.1, Recipe 20.3, Recipe 20.4

    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 1 Hosted by Hostway
    Stay green...Green IT