Old 12-08-2006   #1 (permalink)
Be Unique. Be Heard.
 
Jacorre's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 468

Thumbs up [FLASH] 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 ONE

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.

Here's how I set it up:



STEP TWO

On Frame 1 of the Progress Bar layer I inserted a keyframe and drew a red rectangle that's 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 like the following. Why? Because we want the progress bar to fill from left to right!



On the Properties panel, name your progress bar preloader:



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



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? Because 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 with the following:



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



STEP THREE

Alright after that long step 2 let's move on! Now let's get to the script that will actually make this preloader work. On Frame 1 of the Actions layer let's 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. "200" was the width of the progress bar.

STEP FOUR

On Frame 2 of the Actions layer let's 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 now!
__________________

Jacorre Studios Blog
Jacorre is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 12-09-2006   #2 (permalink)
Just unleashed!
 
unleash's Avatar
 
Join Date: Jul 2005
Location: Inbetween
Posts: 2,140
Blog Entries: 9

Nice, and with a little bit of touch up you can get some awesome work!!
__________________
"I haven't failed, I've just found out
10.000 ways that don't work."

~Thomas Edison~
unleash is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 01-07-2007   #3 (permalink)
Registered User
 
Join Date: Dec 2005
Posts: 43

There's just so many ways to make preloaders..

i personally don't find this a very "simple" preloader.

i find this more usefull:

frame 1
Code:
LOADED = Math.round(getBytesLoaded());
TOTAL = Math.round(getBytesTotal());
PERCENT = LOADED / TOTAL;
BAR._width = PERCENT * 250
if (LOADED == TOTAL)
{
    gotoAndPlay( 3 );
}
frame 2
Code:
gotoAndPlay(1);
It doesn't include the 100 text thingy though.
__________________
ima young wannabe graphical artist
sami1337 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 01-22-2007   #4 (permalink)
Sheep Worrier
 
Man1c M0g's Avatar
 
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,061
Blog Entries: 14

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
Great tutorial! Its now online over @ BioRUST.com :: Tutorials >>
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash Player 9 Problems notjustgraphics Flash & Dynamic Media 13 04-07-2008 05:04 PM
images in flash ecntrc Flash & Dynamic Media 2 01-12-2007 02:37 AM
[Flash] Simple Gallery AirGuitar Tutorial Submission 3 08-12-2006 06:03 PM


All times are GMT +1. The time now is 11:06 AM.
Content Relevant URLs by vBSEO 3.2.0 RC7

Design & Content © BioRUST 2007 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT