Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website.  Home Flash & Swish Flash Tutorials Super Preloader

Super Preloader


Making a preloader is a common topic for tutorials, but here's a new twist: download rate/remaining time. It'll look something like this:

Super Preloader

In order to follow along, you should already know how a preloader works and the roles that _root.getBytesLoaded() and _root.getBytesTotal() play in preloader creation. I've setup my preloader with a progress bar and a percentage text field as well as the download speed and time remaining. Here's the code for my preloader:

_root.loadedBytes = _root.getBytesLoaded();
_root.totalBytes = _root.getBytesTotal();
if (_root.loadedBytes == _root.totalBytes) {
    _root.playB._alpha = 100;
    _root.pbar._visible = false;
    _root.timeRemain._visible = false;
    _root.loadedkbytes._visible = false;
} else {
    _root.percentageOutput = int((_root.getBytesTotal()/_root.getBytesTotal())*100);
    _root.loadedkbytes._x = _root.pbar._x+(4*_root.percentageOutput);
    _root.pbar._xscale = _root.percentageOutput;
    _root.BytesSec = (_root.loadedBytes)/(getTimer()/1000);
    _root.timeRemaining = Math.floor((_root.totalBytes-_root.loadedBytes)/_root.BytesSec);
    if (getTimer()>500) {
        _root.pbar._alpha = 100;
        _root.loadedkbytes.text = _root.percentageOutput+"%";
        _root.timeRemain.text = _root.timeRemaining+" seconds remaining @ "
            +(Math.floor(_root.BytesSec/1024*100))/100+"Kb/sec";
    }
}

What it does is the following:

  1. Get the total bytes and bytes loaded.
  2. Check to see if the total and the current byte counts are equal, if so, skip to step 9.
  3. Calculate the percentage done and display it.
  4. Update the progress bar with the current percentage.
  5. Calculate bytes/sec download speed.
  6. Calculate the time remaining.
  7. If it's been more than .5 seconds, show the text fields and progress bar.
  8. Go to step 1.
  9. Hide the text fields and progress bar and show the "Play" button.

The "magic" is just 2 lines:

_root.BytesSec = (_root.loadedBytes)/(getTimer()/1000);
_root.timeRemaining = Math.floor((_root.totalBytes-_root.loadedBytes)/_root.BytesSec);

All this code does is takes the bytes loaded and devides them by the elapsed time since the movie was opened and then divides the bytes remaining by the current download speed to get the download time remaining.

That's about it. Download the source and poke around a bit.

Source .fla (Flash MX 2004 format)



Author's URL: FlashSandbox
Final results of our readers
New!
Passed through all the steps? Share your result!
Your result will be premoderated.
Please make sure you choose the right image.
 
 



Captcha

*Required fileds
Our Flash tutorials provide you with step-by-step instructions on how to create beautiful Flash animations and integrate them into your website. More Flash Tutorials: Featured Materials | Fresh Materials | More Flash Tutorials at FlashPerfection.com

Reader's comments
comments blaa blaa June 12, 2010 says:
This does not work, All I see is some play button & if I click I see clouds image, there is no seconds remaining cout down or anything
Reply
Add comments to "Super Preloader"

Captcha