How to Make A Preloader In Flash (AS2)
December 25, 2009 in Actionscript 2 Tutorials
Introduction
A useful tutorial for those who are still in the process of learning Actionscript 2, or maybe they know Actionscript 2 but are not sure how to create a preloader. No problem either way or another because we have your back. We’re going to show you how to create a preloader using the power of Flash’s awesome language Actionscript; in this case, Actionscript 2.
What is a preloader? What’s the purpose for one?
A preloader shows you the amount of data downloaded before continuing with a Flash module. You’ll find these in Flash games and Flash toons. Many programmers like to make their preloaders in a bar type format; a case when a bar fills a stroke every time it loads data, showing you how long the video or game will be finished. The bar preloader is the style I’ll be showing you; it’s more modern.
If preloaders are shown in games and movies, why not YouTube and other sites?
YouTube and other video sharing sites do have preloaders but not how you think it is. You see, YouTube and most of the video sharing sites do something called stream. They stream their videos meaning the video is playing and downloading in the background at the same time. Do you really want to wait for a 3GB video download first and then play? As I said previously, their preloaders show when the video is playing and reaches a limit where the video is not yet downloaded; it will stall, preload the video, and then continue streaming.
Video Tutorial
Here’s another video that I made. Watch carefully to where you import this script.
Actionscript (WATCH VIDEO FIRST)
Here’s the Actionscript for the preloader. Be sure to watch the video to understand where you import this script (I said that already, sorry.)
//########################################################
// PRELOADER SOURCE CODE - CODE BY FlashWizard@funtut.com
//########################################################
// stop the video to allow the preloader to do it's work.
stop();
// your made progress bar default width will be set to 0
var pc = 0;
// setting function
this.onEnterFrame = function(){
// everytime bytes are loaded, your made progress bar will add on a pixel from 0 to your desired width
pc = Math.floor((_root.getBytesLoaded() /_root.getBytesTotal()) *100);
// bar will animate the loading process from left to right
this.bar._xscale = pc;
// when preloader is complete showing the download progress
if (pc == 100 && !isNAN(pc)){
// stop the process
delete this.onEnterFrame;
// and continue playing
_root.play()
}
}
That’s about it. The preloader should be finished. Hoped you liked this tutorial. Please rate and leave a comment