First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Chris Berry | Website: http://www.bezzanet.zzn.com

Preloader Tutorial


In this tutorial you will learn how to create a preloader that will return a percentage. This percentage can then be used for things such as a preloader bar. Preloaders that work out percentages are important because they give the users of your site feedback of how much of your flash content is loaded. For this tutorial I expect you to have a basic knowledge of flash and can navigate around freely within the flash interface. I also expect you to have a basic actionscripting knowledge and be able to understand the basic scripts in this tutorial. This tutorial has been writen for use in Flash MX, it takes advantage of some of the added features including text box instance names. If you don't have mx, remember to use the textVariable property instead of the instance name.


1) we'll start off by creating a new movie and adding three keyframes. To do this you can select the first frame and press the F6 key twice. On the first frame make a dynamic text box (text tool>properties> dropdown menu > "dynamic"). Give this text box the instance name of "myOutput". Now copy this text box and paste it in the second frame of the movie. In the third frame put an image or sound file so we will be able to test this preloader latter.

2) Select the first frame and open the actionscript window. If your Actionscript window is set to "Beginner" then click the button in the top right corner of the window and select "Advanced" from the menu, this allows you to freely type and edit code. Now we will write the following code under the first frame

percent = Math.floor(getBytesLoaded()/getBytesTotal()*100);
myOutput.text = percent + "% is loaded";

percent is a variable that we will store how much of the movie is loaded in. getBytesLoaded() retrives the amount of bytes loaded, getBytesTotal() retrives the total size of the movie. when you put these two things over each other and times by 100, you will get the percentage of the movie loaded. The Math.floor() rounds the number to the nearst whole number.

3) In the second frame of the movie clip enter the following code in the actionscript window.

if (percent == 100){

This checks to see if "percent" is equal to 100, if it is, go to the third frame, if its not, goto the first frame.

4) On the fourth frame put a "stop();", this ensures that the movie stops at the last frame and doesn't keep going.

I hope you were able to learn something from this tutorial, if theres any questions please feel free to contact me through the source guru message boards at www.sourceguru.eu.org, or by email to buds_a_bird@hotmail.com. If you want to you can check out my site www.bezzanet.zzn.com and view some of my flash experiments.

» Level Basic

Added: 2002-12-18
Rating: 8 Votes: 247
(10 being the highest)
» Author
Flash and website designer
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.