A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11303 Flash Movies | 7 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Nitin Tikhe
» Title: Cart
» Description: This Animation Tut is a fun and useful for kids below 15 years. Watch the Flag, Doors, Stick and Horse movements.
» More by Nitin Tikhe


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 6008 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Banana Swimwear
» Description: This is a banana swim wear interactive catalog we designed and animated in Flash


Random Links | Add your own Flash Related Links
Flash Tutorials 1255 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make flash video player for broadcasting live streaming video / TV on website
» How to convert the project file of Flash Demo Builder 2.0 into FLV file
» FLV to PSP for Mac - How to convert YouTube video to PSP on mac
» How to Convert FLV to MP4 for Playback on iPod
» how to download and convert youtube video to AVI with Leawo Free FLV converter
» Flash Multi-player Game Tutorial - TicTacToe
» How to make Flash elearning tutorials with screen recorder?
» Fader API:Slideshow with MovieClips on stage
» How to convert MS PPT file into an FLV File
» Unknown Tag: Title10
Random Tutorial | Add Site

Network Design Manager
The Computer Merchant, Ltd
US-VA-Hampton

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Actionscripting

Categories Smooth Preloading Tutorial
Author: black

 
Page 2
«prev 1 2


Okay, let's take a look at this line by line to see what's going on.

_root.stop(); This stops the root movie's timeline so as not to try displaying unloaded objects. The next two lines of actionscript are creating variables. We're using strict datatyping here. By declaring what sort of data a variable holds, Flash can check during compilation for mis-assignment and the like, generally saving you a headache here and there. Therefore if I accidentally assign "America is a cultural slaughterhouse" to percLoaded or newPercLoaded, Flash will catch the error and let me know I've muffed up. To assign that to a variable whilst maintaining strict datatyping, I'd have to have a variable of type String... it would look like this:
var americaQuote:String="America is a cultural slaughterhouse";
This datatyping convention also shows up in our preload function. More on that later.

onEnterFrame = preload;
onEnterFrame is a method of the MovieClip class that iterates at the same frequency as your movie's framerate. Here we call the preload function 12 times per second (assuming you haven't changed the framerate).

function preload():Void { This declares a function. It has no parameters and thus the parantheses are empty. the :Void lets the Flash compiler know that this function has no return value.

newPercLoaded = Math.floor(_root.getBytesLoaded()/_root.getBytesTotal()*100);
If you've been looking into preloaders, you've undoubtedly seen this before. This takes the number of loaded bytes, divides that by the whole of the file's bytes and multiplies it by 100. The Math.floor part rounds the insane decimal this yields down to an integer. I store this integer in my variable newPercLoaded.

lb._xscale=percLoaded=percLoaded+(newPercLoaded-percLoaded)*.2; This is the backbone of our smooth preloader. Because newPercLoaded now contains the percentage of the movie that has loaded into the Flash Player and a MovieClip's _xscale property is a percentage of the instance's width, we can use these two in tandem to do anything we please in a nice tidy fashion. So, what happens is I set our bar's _xscale to percLoaded. percLoaded, in turn, is equal to itself plus newPercLoaded minus itself divided by 5. This is syntactically verbose yet not complex. Let's take a disjointed look at what this is doing. Let's say the movie loads instantaneously. This would set newPercLoaded to 100. We've already set percLoaded to 0, and assigned lb's _xscale to percLoaded. So percLoaded = 0+(100-0)*.2, or, computed, 20. So the first iteration of our preload function sets lb's width to 20%. The next iteration would look like this:
percLoaded = 20+(100-20)*.2 or 36. This continues at 12 times per second easing us towards 100, thus eliminating that jerky movement.

if(percLoaded>99.9&&newPercLoaded==100){ this checks whether percLoaded is greater than 99.9 and that newPercLoaded is infact 100. Careful with checking for equality in if statements. One equal sign (=) actually sets what you're checking... so if you check if variable x = 50, it should look like this: if(x==50), not if(x=50). The latter will always return true, thus setting x to 50 and without fail executing the subsequent statements.

stop(); Given we are loaded (see above), we want this clip to stop.

_root.nextFrame; Now that the movie has loaded advance the root movie to the next frame.

delete this.onEnterFrame; We don't want this to continue using system resources so we delete it!

That's it-

«prev 1 2

» Level Basic

Added: : 2005-03-08
Rating: 6.48 Votes: 31
Hits: 2260
» Author
black is the new black
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments