All-in-one preloader

Hello,

I’ve been trying to get this all-in-one preloader to work for some time now, but apparantely there are still some bugs. The idea is to distill a class or component out of this somewhere in the future, but for now it just needs to meet some specific needs (_root.container.getBytesLoaded, no JPG or MP3 support yet, etc etc.).

So, on the first frame of my movie I have this:

var loading:Boolean = false;
	
loadArray = new Array("main", "main.swf", "portFolio.xml");
infoArray = new Array("navigation", "XML", "content");

While this piece of code is placed on the preloader mc:

onClipEvent(enterFrame){
	//trace(_root.loading);
	if(_root.loading == false){
		_root.loading = true;
		this.loaderBar._xscale = 1;
		
		newLoad = _root.loadArray.shift();
		this.loaderStatus.text = "Loading " + _root.infoArray.shift();
		
		trace("Loading: " + newLoad);
		
		if(newLoad == "main"){
			// Load the main movie clip
			var loadedBytes:Number = _parent.getBytesLoaded();
			var totalBytes:Number = _parent.getBytesTotal();
			var perLoaded:Number = Math.floor((loadedBytes / totalBytes) * 100);

			this.loaderBar._xscale = perLoaded;
			if(perLoaded == 100){
				_root.loading = false;
			}
		}else{
			 var extVar:String = newLoad.substr(-3, 3);
			 
			 trace(extVar);
			
			if(extVar == "swf"){
				// The content to be loaded is an SWF
				// Load the swf in a container called containerMC
				_root.containerMC.loadMovie(newLoad);
				
				var loadedBytes:Number = _root.containerMC.getBytesLoaded();
				var totalBytes:Number = _root.containerMC.getBytesTotal();
				var perLoaded:Number = Math.floor((loadedBytes / totalBytes) * 100);
				
				this.loaderBar._xscale = perLoaded;
				if(perLoaded == 100){
					_root.loading = false;
				}
			}else if(extVar == "xml"){				
				// The content to be loaded is an XML File
				// Load the XML file into an xmlObject.
				var xmlDoc:XML = new XML();
				xmlDoc.load(newLoad);
				
				var loadedBytes:Number = xmlDoc.getBytesLoaded();
				var totalBytes:Number = xmlDoc.getBytesTotal();
				var perLoaded:Number = Math.floor((loadedBytes / totalBytes) * 100);
				
				this.loaderBar._xscale = perLoaded;
				if(perLoaded == 100){
					_root.loading = false;
				}
			}else if(extVar == "mp3"){
				//mp3 preload code goes here
			}else if(extVar == "jpg"){
				//JPEG preload code goes here.
			}
		}
	}
}

Any help would be greatly appreciated.

You Are on the wrong way )
To much trash.

Everything you load has it’s own bitesLoaded and bytesTotal (swf, jpeg,xml, mp3, and txt files)
You just need to create a preloader MC then set the link to preloaded object and set onEnterFrame event.

If you are trying to do a TOTAL preloaderv (that shows overAllprogress) - just collect all the TotalBytes of preloading objects, all the loaded bytes - and compute the needed value.