Introduction
Ok, this is one of the most simplist things to do, since you dont even need graphics or anything like that. In fact, all it really needs is 3 to 5 lines of code and a Dynamic text box!
the variable
In the actions of the first frame of your movie (right click on the frame - actions) put this code:
a = getBytesLoaded(); b = getBytesTotal(); c = Math.ceil((a/b)*100)+"%";
What do they do
a and b do what they say. a find out how many bytes have been loaded and set variable 'a' as that value and b finds out how many bytes need to be loaded (and again sets 'b' as that value)
C works out (A/B)X100 (the percentage loaded) and then the +"%" out side of the maths section adds the % sign to the end of what is shown in the text box (made later)
Putting the code to use!
Ok, so we got the basic code, create a keyframe in frame two of your actions layer (or where ever you put your frame related actions) and put
gotoAndPlay (1);
This makes the variables we made before update themselfs.
Also add to the actions if the first frame:
if (a == b) {
nextScene ();
}
Or what ever you want, such as.
gotoAndPlay (3);
Depending on how you like to manage your movies.
Displaying the percent loaded.
This is the real easy bit, just add a text box then make it Dynamic (using text options) and set the variable to:
_root.c
Put this text box where you want the percentage to be shown! If you really want to display how many KB has to be loaded and how much has been loaded you need to add the code:
d = Math.floor(a/1024)+"kb"; e = Math.floor(b/1024)+"kb";
to the actions in the first frame.
This sets a and b to display the kb loaded instead of the bytes loaded. You then need to make dynamic text boxs with the varible '_root.d' for kb loaded and '_root.e' for kb total to load.
Ok, so you should now have the ability to make a percentage displaying preloader for flash. Id like to thank Alan Wisternoff for his 'Preloader with Dial Display' tutorial as this is how I learned the basics of the preloader in flash 5.
Thank you for taking the time to read my tut. :)
discuss this topic to forum
