Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

Simple Flash Preloader


As the size of your flash file increases, so too does the time it takes to load it. Visitors to your site may get irritated if they have to wait for the animation to load. Using a preloader can help that - It will load all the necessary pieces prior to displaying the animation. It will also show its progress so visitors will be able to see how much is loaded and hopefully wait for it to finish!

Step 1
What we'll need to do is set up the necessary layers. We'll need one for Actions, which is the scripts being used for the preloader. The Text layer will show the percentage complete for the preloader as text. The Stroke is just the stroke outside the progress bar. We want the progress bar to fill up within the stroke. The Progress bar will visually show the preloader's progress by using a rectangle. And finally, the last layer is the actual animation you want playing after the preloader has finished.


Step 2
On Frame 1 of the Progress Bar layer I inserted a keyframe and drew a red rectangle 200 pixels wide and 20 pixels high:

I then selected the progress bar and hit F8 to make it a movie clip. Make sure the registration point is set as below. Why? Well... because we want the progress bar to fill from left to right!

In the Properties panel, name your progress bar preloader:

On Frame 1 of the Stroke layer, I inserted a keyframe and drew the following rectangle:

The above is just a stroke with no fill. The Stroke layer is above the Progress Bar layer. Why did we do it this way? Its quite simple really - we want the progress bar to fill within the stroke area. If we added a stroke to the progress bar itself, it wouldn't look right!

On Frame 1 of the Text layer I inserted a keyframe and added a text box as follows:

I then selected the text box and on the Properties panel I set it to Dynamic Text and named it loadText:




Step 3
Now that we have laid all the groundwork for our animation we can get to the script that will actually make this preloader work. On Frame 1 of the Actions layer add the following code:

var amountLoaded:Number = _root.getBytesLoaded()/_root.getBytesTotal();
preloader._width = amountLoaded * 200;
loadText.text = Math.round(amountLoaded * 100) + "%";

I highlighted the important pieces in the script. "preloader" was the name we gave the progress bar. "loadText" was the name we gave the text box. And "200" was the pixel width of the progress bar.



Step 4
On Frame 2 of the Actions layer add the following code:

if(_root.getBytesLoaded() == _root.getBytesTotal()) {
gotoAndPlay(3);
}

else {
gotoAndPlay(1);
}

What this script is saying is if the bytes that have been loaded equals the total number of bytes in the file then the preloading is done and you can go to frame 3 and begin playing the animation. If the bytes loaded does not equal the total then go back to frame 1 and keep preloading.

NOTE: You may be asking why frame 3 has blank frames for the Text, Stroke, and Progress Bar layers. This is because we don't want the preloader to display once the actual animation is playing, which begins on frame 3. Also, you may not even see your preloader display if your file size isn't that big. What you could do is add a few more objects to your design and then go to Control > Test Movie. The flash player should appear and your movie will play. On the Flash player menu go to View > Download Settings and choose the slowest setting. Then test the movie again and you should see your preloader working.

I hope you found this tutorial useful. Feel free to contact me should you have any questions.

- Tutorial written by Jacorre

Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments

User:  jefe317 (#51508)
Date: Sun Jul 13, 2008. 19:21:11

Post #2 of 2

I tried doing this tutorial in Flash CS3 Pro, however, it didn't work.

I followed everything to a tee, but i get 4 very similar errors when i test my movie.

the error says:
Location: scene 1, layer 'actions', frame 1, line 1
Description : 1120: Access of undefined property _root.
Source: var amountLoaded:Number = _root.getBytesLoaded() / _root.getBytesTotal();



thanks for your help!

Reply to this post


User:  goldmask (#51368)
Date: Tue Jul 08, 2008. 06:42:11

Post #1 of 2

Quote from Man1c M0g;36877:
This is a thread to discuss the Simple Flash Preloader tutorial. Please keep all posts on-topic, don't spam, and read the entire thread BEFORE you post - any issues you have could be answered deeper within the thread.


what Script on Frame 3 of the Actions layer add?

should I add " stopgotoAndStop();" on Frame 3 of the Actions layer?

Reply to this post


--- View Entire Thread ---
Amazing Font Pack!

Featured Tutorialsmore

Inset Lines
Inset Lines
- Adobe Photoshop -
Razor Stryke Logo
Razor Stryke Logo
- Adobe Photoshop -
Night Lights (w/ A...
Night Lights (w/ A...
- Macromedia Flash -
Advanced Abstract ...
Advanced Abstract ...
- Maxon Cinema 4D -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 887 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1052 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1054 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1935 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1832 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14441 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2751 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2772 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3439 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2356 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2499 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2798 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673