First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Chris Berry | Website: http://www.bezzanet.zzn.com

Preloader Tutorial

Introduction

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.

Tutorial

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){
gotoAndStop(3);
}else{
gotoAndPlay(1);
}

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!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.