A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


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

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


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

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Trading Customer Accounting (IL)
Next Step Systems
US-IL-Chicago

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.31 Votes: 32
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
     
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs