# All-in-one preloader

**URL:** <https://forum.kirupa.com/t/all-in-one-preloader/205013>\
**Category:** flash\
**Created:** [October 25, 2006, 12:09pm UTC](https://forum.kirupa.com/t/all-in-one-preloader/205013 "2006-10-25T12:09:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doccie](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/doccie/32/2944_2.png) [@Doccie](https://forum.kirupa.com/u/Doccie)\
**Post date:** [October 25, 2006, 12:09pm UTC](https://forum.kirupa.com/t/all-in-one-preloader/205013/1 "2006-10-25T12:09:26Z")

</div>

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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![MureJIb](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/murejib/32/2994_2.png) [@MureJIb](https://forum.kirupa.com/u/MureJIb)\
**Post date:** [October 25, 2006, 3:46pm UTC](https://forum.kirupa.com/t/all-in-one-preloader/205013/2 "2006-10-25T15:46:58Z")

</div>

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.
