Sunday, January 23, 2011

Creating your own Flash Preloader

We see preloaders in many flash applications these days. An animation, a video, or a movie, or even a game, start mostly with a preloader now. Once the preloader is shown, only then the actual animation starts playing.

What is a Preloader ?

A preloader is a horizontal bar that keeps scaling up and the intensity of the scale depends on the loaded bytes of the file. When the files are loaded completely, the bar reaches its maximum length. The intensity of the bar load-scale is calculated as per the following formula:

                          load-scale = (bytes loaded) / (total no of bytes)

How to create a simple Preloader ?

Step 1: Create a horizontal bar, and convert it into a movie clip.


Step 2: Give an instance name, say, loadMC.



Step 3: Create a dynamic text field, in the same layer (though not mandatory).



Step 4: Give instance name to this text field as well, say, loadTxt



Step 5: Create another layer for the code / script.



Step 6: Put a stop( ) to the first frame, and then add an event listener, ENTER_FRAME, so that the code is executed as soon as the first frame is encountered, and because there is no other frame, the code would keep on executing. Then the files-load percentage is calculated by the above formula, which is displayed in the dynamic text field.



Step 7: Once this is done, press Ctrl+enter. You will get the swf file, displaying the complete horizontal bar and displaying "100%" text below it. Now press Ctrl+enter again, and then the actual preloader function is observed. If not, then go to the "view" options in the swf window and select the download speed according to your requirements and convinience.

No comments:

Post a Comment