This is one of the first AS2 scripts I am going to publish. It is the script for a simple virtual preloader, which does not require any objects on stage. All objects are created by the script. All you need to do is put one line of script in the first frame of the flash movie, which specifies all parameters. Comments in the script are indicated by //in red.

The Script


******************** Start ********************
//class definition
class FlashscriptLoader {
	private static var xDistance:Number;
	private static var yDistance:Number;
	private static var barHeight:Number;
	private static var barColor:Color;
	private static var frameName:String;
	private static var movieLoader:String;
	private static var outLine:String;
	private static var perLoaded:Number;
	private static var loadedBytes:Number;
	private static var totalBytes:Number;
	private static var bytes:Number;
	private static var frame:Number;
	private static var bytesField:String;
	private static var frameField:String;
	private static var totalField:String;

//constructor
	function FlashscriptLoader(xDistance,yDistance,barHeight,barColor,frameName){
	   loadTheMovie(xDistance,yDistance,barHeight,barColor,frameName);
	}
	
	private function loadTheMovie(xDist,yDist,bHeight,bColor,fName):Void{

//passing the parameter variables
	   xDistance = xDist;
	   yDistance = yDist;
	   barHeight = bHeight;
	   barColor = bColor;
	   frameName = fName;

//creating empty movieclips for loaderbar
	   _root.createEmptyMovieClip("outLine",1);
	   _root.createEmptyMovieClip("movieLoader",2);    

//creating the outline for loaderbar
	   _root.outLine.lineStyle(1, 0x000000, xDist);
	   _root.outLine.moveTo(xDist-1,yDist-1);
	   _root.outLine.lineTo(xDist+102,yDist-1);
	   _root.outLine.lineTo(xDist+102,yDist+bHeight+2);
	   _root.outLine.lineTo(xDist-1,yDist+bHeight+2);
	   _root.outLine.lineTo(xDist-1,yDist-1);

//creating textfields
	   _root.createTextField("bytesField",3,xDist-70,yDist+bHeight+20,100,15); 
	   _root.bytesField.textColor = "0xffffff";
	   _root.createTextField("frameField",4,xDist+90,yDist+bHeight+20,100,15);
	   _root.createTextField("totalField",5,xDist+20,yDist+bHeight+50,100,15); 

//loading function
	   _root.onEnterFrame = function() {

//getting total bytes
	       totalBytes = _root.getBytesTotal();

//loded bytes defining
	       loadedBytes = _root.getBytesLoaded();

//bytes loaded
            bytes = Math.ceil((loadedBytes/1024)*1000);

//% loaded
	       perLoaded = Math.ceil((loadedBytes/totalBytes) * 100);

//defining the loading status for loaderbar
	       frame = Math.ceil(loadedBytes/(totalBytes/100)+xDist); 

//creating the fill for loaderbar
            _root.movieLoader.lineStyle(1, bColor, xDist);
	       _root.movieLoader.beginFill(bColor,xDist);
	       _root.movieLoader.moveTo(xDist,yDist);
	       _root.movieLoader.lineTo(frame,yDist);
	       _root.movieLoader.lineTo(frame,yDist+bHeight);
	       _root.movieLoader.lineTo(xDist,yDist+bHeight);
	       _root.movieLoader.lineTo(xDist,yDist);

//showing the bytes and % loaded in textfield
	       _root.totalField.text = "total bytes: "+totalBytes; 
	       _root.bytesField.text = "bytes loaded: "+bytes;
	       _root.frameField.text = "% loaded: "+perLoaded;

//after loading remove all objects and go to indicated frame
	       if (loadedBytes >= totalBytes) {
	           removeMovieClip(_root.movieLoader);
	           removeMovieClip(_root.outLine);
	           removeMovieClip(_root.bytesField);
	           removeMovieClip(_root.frameField);
	           removeMovieClip(_root.totalField);
                _root.gotoAndPlay(fName);
                delete _root.onEnterFrame;
	       }
	   }
	}
}

******************** End of Script ********************
Parameters:
  • xDistance: x position of loaderbar
  • yDistance: y position of loaderbar
  • barHeight: height of the loaderbar
  • barColor: hexadecimal color value for the loaderbar fill
  • frameName: name of the frame to go when movie is loaded
Example (put this script in the first frame of your movie):
stop();
var myLoader:FlashscriptLoader = new FlashscriptLoader(x,y,height,color,"framename");

If you use a different path because you want to put your script into a folder you have to change the class name like foldername.FlashscriptLoader.