Return to Snippet

Revision: 54384
at December 23, 2011 23:13 by burnandbass


Updated Code
/*
Author : Chrysto Dimchev ( burnandbass [at] gmail [.] com )
*/
package  {
	
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	import flash.system.System;
	
	public class ChromeLoader extends EventDispatcher {
		
		private static var _content:Array = [];		
		private static var _contentNames:Dictionary = new Dictionary(true);
		
		private var _loadersCompleted:Number = 0;
		private var _loaders:Array = [];
		private var _loaderNames:Array = [];
		private var _maxTries:Number = 0;
		
		private var _site:String = "";
		private var _backupUrl:String = "";
		
		private var _finished:Boolean = false;
		
		/* CONSTRCTOR
			pass params:
			@site --> url to prepend the loaders (expl: "http://site.com/images")
			@backupURL --> backup url, the loader will try to load the same picture, but with this string instead ot @site (expl: http://sitebackup.com/images)
		*/
		public function ChromeLoader(site:String = null, backupURL:String = null):void {
			if(site){ _site = site }
			if(backupURL){ _backupUrl = backupURL }
		}
		
		////	PUBLIC
		
		//load images/MovieClips, pass array of items to load
		public function loadContents(_items:Array):void{
			for(var i:Number = 0; i< _items.length; i++){
				_loaderNames.push( _items[i] );
			}
			
			loadContent(_loaderNames[_loadersCompleted]);
		}
		
		//returns loader for given ID
		public function getLoader(_contentID:Number):Loader{
			if(_loaders[_contentID]){
				return _loaders[_contentID];
			} else {
				trace("[ChromeLoader: ] loader by this ID not found!");
				return null;
				//return new MovieClip();  //uncomment if you don't want to get RuntimeError
			}
		}
		
		//return movie clip (avm1/avm2) for given ID
		public function getMovieClip(_clipID:Number):MovieClip{
			if(_loaders[_clipID]){
				return _loaders[_clipID].content as MovieClip
			} else {
				trace("[ChromeLoader: ] MovieClip by this ID not found!");
				return null;
				//return new MovieClip();  //uncomment if you don't want to get RuntimeError
			}
		}
		
		//Unloads the loaders, clears the static holders
		public function clear():void{
			try{
				_content.splice(0, _content.length);
				 
				 //clean the dictionary, otherwise this may conflict on reload
				for(var i:Number = 0; i< _loaderNames.length; i++){
					delete( _contentNames[_loaderNames[i]] )
				}
				
				//clean the loaders
				for each(var loader:Loader in _loaders){
					//1 || removes all listeners
					loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.NETWORK_ERROR, onError);
					//2 || removes it from stage
					if (loader.parent) {
						loader.parent.removeChild(loader);
					}
					//3  || unload content
					if (loader.hasOwnProperty("unloadAndStop")) {      //fp10
						loader.unloadAndStop(true); 
					} else {
						loader.unload();
					}
					
					//removes it from memory for all
					loader = null;
				}
			
			System.gc();
			
			} catch(error:Error){
				trace("[ChromeLoader error on destroy: ] " + error.message);
			}
		}
		
		////	PRIVATE
		
		private function loadContent(_cleanUrl:String):void{			
			_maxTries = 0;
			var contentLoader:Loader = new Loader();
			contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
			contentLoader.load( new URLRequest( _site + _cleanUrl  ));
			trace("loading: " + String(_loadersCompleted+1) + " out of " + _loaderNames.length + " | " + _site + _cleanUrl);
		}
		
		private function onComplete(event:Event):void {
			_loaders.push(event.target.content.parent as Loader);			
			
			_content.push( event.target.content.parent );
			
			_contentNames[String(_loaderNames[_loadersCompleted])] = event.target.content.parent as Loader;
			
			_loadersCompleted++;
						
			if(_loadersCompleted < _loaderNames.length){
				loadContent(_loaderNames[_loadersCompleted]);
			} else {
				_finished = true;
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		private function onError(event:Event):void{
			_maxTries++;
			if(_maxTries < 3){
				var contentLoader:Loader = new Loader();
				contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
				contentLoader.load( new URLRequest( _backupUrl + _loaderNames[_loadersCompleted]  ));
				trace("[ERROR] on loading " + _loaderNames[_loadersCompleted] + " .Loading backup file: " + _backupUrl + _loaderNames[_loadersCompleted]);
			} else {
				trace("[ChromeLoader: ] on Error error - max tries reached! Load never completed!");
			}
			
			//removes the listeners from failed loader, it is ready for Garbage Collection
			(event.target as LoaderInfo).removeEventListener(Event.COMPLETE, onComplete);	
			(event.target as LoaderInfo).removeEventListener(IOErrorEvent.IO_ERROR, onError);	
			(event.target as LoaderInfo).removeEventListener(IOErrorEvent.NETWORK_ERROR, onError);
		}
		
		//// 	PUBLIC STATIC
		
		//returns DisplayObject for given ID (the ID is the index position of the item in the loading names array)
		public static function getContent(_contentID:Number):DisplayObject{
			if(_content[_contentID]){
				return _content[_contentID];
			} else {
				trace("[ChromeLoader: ] Content with this ID( " + _contentID + " )not found!");
				return null;
				//return new MovieClip();  //uncomment if you don't want to get RuntimeError
			}
		}
		
		//get content for given name, just pass name from the array you loaded
		public static function getContentByName(_contentName:String):DisplayObject{
			if(_contentNames[_contentName]){
				return _contentNames[_contentName];
			} else {
				trace("[ChromeLoader: ] Content with this NAME( " + _contentName + " )not found!");
				return null;
				//return new MovieClip();  //uncomment if you don't want to get RuntimeError
			}
		}
		
		//// GETTERS /  SETTERS
		
		//returns true if the loader have loaded all images
		public function get finished():Boolean{
			return _finished;
		}
		
	}//end
}

Revision: 54383
at December 23, 2011 23:01 by burnandbass


Updated Code
/*
Author : Chrysto Dimchev ( burnandbass [at] gmail [.] com )
*/
package  {
	
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	import flash.system.System;
	
	public class ChromeLoader extends EventDispatcher {
		
		private static var _content:Array = [];		
		private static var _contentNames:Dictionary = new Dictionary(true);
		
		private var _loadersCompleted:Number = 0;
		private var _loaders:Array = [];
		private var _loaderNames:Array = [];
		private var _maxTries:Number = 0;
		
		private var _site:String = "";
		private var _backupUrl:String = "";
		
		/* CONSTRCTOR
			pass params:
			@site --> url to prepend the loaders (expl: "http://site.com/images")
			@backupURL --> backup url, the loader will try to load the same picture, but with this string instead ot @site (expl: http://sitebackup.com/images)
		*/
		public function ChromeLoader(site:String = null, backupURL:String = null):void {
			if(site){ _site = site }
			if(backupURL){ _backupUrl = backupURL }
		}
		
		////	PUBLIC
		
		//load images/MovieClips, pass array of items to load
		public function loadContents(_items:Array):void{
			for(var i:Number = 0; i< _items.length; i++){
				_loaderNames.push( _items[i] );
			}
			
			loadContent(_loaderNames[_loadersCompleted]);
		}
		
		//returns loader for given ID
		public function getLoader(_contentID:Number):Loader{
			if(_loaders[_contentID]){
				return _loaders[_contentID];
			} else {
				trace("[ChromeLoader: ] loader by this ID not found!");
				return null;
			}
		}
		
		//return movie clip (avm1/avm2) for given ID
		public function getMovieClip(_clipID:Number):MovieClip{
			if(_loaders[_clipID]){
				return _loaders[_clipID].content as MovieClip
			} else {
				trace("[ChromeLoader: ] MovieClip by this ID not found!");
				return null;
			}
		}
		
		//Unloads the loaders, clears the static holders
		public function clear():void{
			try{
				_content.splice(0, _content.length);
				 
				 //clean the dictionary, otherwise this may conflict on reload
				for(var i:Number = 0; i< _loaderNames.length; i++){
					delete( _contentNames[_loaderNames[i]] )
				}
				
				//clean the loaders
				for each(var loader:Loader in _loaders){
					//1 || removes all listeners
					loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.NETWORK_ERROR, onError);
					//2 || removes it from stage
					if (loader.parent) {
						loader.parent.removeChild(loader);
					}
					//3  || unload content
					if (loader.hasOwnProperty("unloadAndStop")) {      //fp10
						loader.unloadAndStop(true); 
					} else {
						loader.unload();
					}
					
					//removes it from memory for all
					loader = null;
				}
			
			System.gc();
			
			} catch(error:Error){
				trace("[ChromeLoader error on destroy: ] " + error.message);
			}
		}
		
		////	PRIVATE
		
		private function loadContent(_cleanUrl:String):void{			
			_maxTries = 0;
			var contentLoader:Loader = new Loader();
			contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
			contentLoader.load( new URLRequest( _site + _cleanUrl  ));
			trace("loading: " + String(_loadersCompleted+1) + " out of " + _loaderNames.length + " | " + _site + _cleanUrl);
		}
		
		private function onComplete(event:Event):void {
			_loaders.push(event.target.content.parent as Loader);			
			
			_content.push( event.target.content.parent );
			
			_contentNames[String(_loaderNames[_loadersCompleted])] = event.target.content.parent as Loader;
			
			_loadersCompleted++;
						
			if(_loadersCompleted < _loaderNames.length){
				loadContent(_loaderNames[_loadersCompleted]);
			} else {
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		private function onError(event:Event):void{
			_maxTries++;
			if(_maxTries < 3){
				var contentLoader:Loader = new Loader();
				contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
				contentLoader.load( new URLRequest( _backupUrl + _loaderNames[_loadersCompleted]  ));
				trace("[ERROR] on loading " + _loaderNames[_loadersCompleted] + " .Loading backup file: " + _backupUrl + _loaderNames[_loadersCompleted]);
			} else {
				trace("[ChromeLoader: ] on Error error - max tries reached! Load never completed!");
			}
			
			//removes the listeners from failed loader, it is ready for Garbage Collection
			(event.target as LoaderInfo).removeEventListener(Event.COMPLETE, onComplete);	
			(event.target as LoaderInfo).removeEventListener(IOErrorEvent.IO_ERROR, onError);	
			(event.target as LoaderInfo).removeEventListener(IOErrorEvent.NETWORK_ERROR, onError);
		}
		
		//// 	PUBLIC STATIC
		
		//returns DisplayObject for given ID (the ID is the index position of the item in the loading names array)
		public static function getContent(_contentID:Number):DisplayObject{
			if(_content[_contentID]){
				return _content[_contentID];
			} else {
				trace("[ChromeLoader: ] Content with this ID( " + _contentID + " )not found!");
				return null;
				//return new MovieClip();  //uncomment if you don't want to get RuntimeError
			}
		}
		
		//get content for given name, just pass name from the array you loaded
		public static function getContentByName(_contentName:String):DisplayObject{
			if(_contentNames[_contentName]){
				return _contentNames[_contentName];
			} else {
				trace("[ChromeLoader: ] Content with this NAME( " + _contentName + " )not found!");
				return null;
				//return new MovieClip();  //uncomment if you don't want to get RuntimeError
			}
		}
		
	}//end
}

Revision: 54382
at December 23, 2011 22:36 by burnandbass


Updated Code
/*
Author : Chrysto Dimchev ( burnandbass [at] gmail [.] com )
*/
package  {
	
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	import flash.system.System;
	
	public class ChromeLoader extends EventDispatcher {
		
		private static var _content:Array = [];		
		private static var _contentNames:Dictionary = new Dictionary(true);
		
		private var _loadersCompleted:Number = 0;
		private var _loaders:Array = [];
		private var _loaderNames:Array = [];
		private var _maxTries:Number = 0;
		
		private var _site:String = "";
		private var _backupUrl:String = "";
		
		
		/* CONSTRCTOR
			pass params:
			@site --> url to prepend the loaders (expl: "http://site.com/images")
			@backupURL --> backup url, the loader will try to load the same picture, but with this string instead ot @site (expl: http://sitebackup.com/images)
		*/
		public function ChromeLoader(site:String = null, backupURL:String = null):void {
			if(site){ _site = site }
			if(backupURL){ _backupUrl = backupURL }
		}
		
		////	PUBLIC
		
		//load images/MovieClips, pass array of items to load
		public function loadContents(_items:Array):void{
			for(var i:Number = 0; i< _items.length; i++){
				_loaderNames.push( _items[i] );
			}
			
			loadContent(_loaderNames[_loadersCompleted]);
		}
		
		//returns loader for given ID
		public function getLoader(_contentID:Number):Loader{
			if(_loaders[_contentID]){
				return _loaders[_contentID];
			} else {
				trace("[ChromeLoader: ] loader by this ID not found!");
				return null;
			}
		}
		
		//return movie clip (avm1/avm2) for given ID
		public function getMovieClip(_clipID:Number):MovieClip{
			if(_loaders[_clipID]){
				return _loaders[_clipID].content as MovieClip
			} else {
				trace("[ChromeLoader: ] MovieClip by this ID not found!");
				return null;
			}
		}
		
		//Unloads the loaders, clears the static holders
		public function clear():void{
			try{
				_content.splice(0, _content.length);
				 
				 //clean the dictionary, otherwise this may conflict on reload
				for(var i:Number = 0; i< _loaderNames.length; i++){
					delete( _contentNames[_loaderNames[i]] )
				}
				
				//clean the loaders
				for each(var loader:Loader in _loaders){
					//1 || removes all listeners
					loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.NETWORK_ERROR, onError);
					//2 || removes it from stage
					if (loader.parent) {
						loader.parent.removeChild(loader);
					}
					//3  || unload content
					if (loader.hasOwnProperty("unloadAndStop")) {      //fp10
						loader.unloadAndStop(true); 
					} else {
						loader.unload();
					}
					
					//removes it from memory for all
					loader = null;
				}
			
			System.gc();
			
			} catch(error:Error){
				trace("[ChromeLoader error on destroy: ] " + error.message);
			}
		}
		
		////	PRIVATE
		
		private function loadContent(_cleanUrl:String):void{			
			_maxTries = 0;			
			var contentLoader:Loader = new Loader();
			contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
			contentLoader.load( new URLRequest( _site + _cleanUrl  ));
			trace("loading: " + String(_loadersCompleted+1) + " out of " + _loaderNames.length + " | " + _site + _cleanUrl);
		}
		
		private function onComplete(event:Event):void {
			
			_loaders.push(event.target.content.parent as Loader);
			
			_content.push( event.target.content.parent );
			
			_contentNames[String(_loaderNames[_loadersCompleted])] = event.target.content.parent as Loader;
			
			_loadersCompleted ++;
						
			if(_loadersCompleted < _loaderNames.length){
				loadContent(_loaderNames[_loadersCompleted]);
			} else {
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		private function onError(event:Event):void{
			
			_maxTries++;
			if(_maxTries < 3){
				var contentLoader:Loader = new Loader();
				contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
				contentLoader.load( new URLRequest( _backupUrl + _loaderNames[_loadersCompleted]  ));
				trace("[ERROR] on loading " + _loaderNames[_loadersCompleted] + " .Loading backup file: " + _backupUrl + _loaderNames[_loadersCompleted]);
			} else {
				trace("[ChromeLoader: ] on Error error - max tries reached! Load never completed!");
			}
			
			(event.target as LoaderInfo).removeEventListener(Event.COMPLETE, onComplete);	
			(event.target as LoaderInfo).removeEventListener(IOErrorEvent.IO_ERROR, onError);	
			(event.target as LoaderInfo).removeEventListener(IOErrorEvent.NETWORK_ERROR, onError);
		}
		
		//// 	PUBLIC STATIC
		
		//returns DisplayObject for given ID (the ID is the index position of the item in the loading names array)
		public static function getContent(_contentID:Number):DisplayObject{
			if(_content[_contentID]){
				return _content[_contentID];
			} else {
				trace("[ChromeLoader: ] Content by this ID not found!");
				return null;
			}
		}
		
		//get content for given name, just pass name from the array you loaded
		public static function getContentByName(_contentName:String):DisplayObject{
			if(_contentNames[_contentName]){
				return _contentNames[_contentName];
			} else {
				trace("[ChromeLoader: ] Content by this NAME not found!");
				return null;
			}
		}
		
	}//end
}

Revision: 54381
at December 23, 2011 22:11 by burnandbass


Updated Code
/*
Author : Chrysto Dimchev ( burnandbass [at] gmail [.] com )
*/
package  {
	
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.utils.Dictionary;
	import flash.system.System;
	
	public class ChromeLoader extends EventDispatcher {
		
		private static var _content:Array = [];		
		private static var _contentNames:Dictionary = new Dictionary(true);
		
		private var _loadersCompleted:Number = 0;
		private var _loaders:Array = [];
		private var _loaderNames:Array = [];
		private var _maxTries:Number = 0;
		
		private var _site:String = "";
		private var _backupUrl:String = "";
		
		
		/* CONSTRCTOR
			pass params:
			@site --> url to prepend the loaders (expl: "http://site.com/images")
			@backupURL --> backup url, the loader will try to load the same picture, but with this string instead ot @site (expl: http://sitebackup.com/images)
		*/
		public function ChromeLoader(site:String = null, backupURL:String = null):void {
			if(site){ _site = site }
			if(backupURL){ _backupUrl = backupURL }
		}
		
		////	PUBLIC
		
		//load images/MovieClips, pass array of items to load
		public function loadContents(_items:Array):void{
			for(var i:Number = 0; i< _items.length; i++){
				_loaderNames.push( _items[i] );
			}
			
			loadContent(_loaderNames[_loadersCompleted]);
		}
		
		//returns loader for given ID
		public function getLoader(_contentID:Number):Loader{
			if(_loaders[_contentID]){
				return _loaders[_contentID];
			} else {
				trace("[ChromeLoader: ] loader by this ID not found!");
				return null;
			}
		}
		
		//return movie clip (avm1/avm2) for given ID
		public function getMovieClip(_clipID:Number):MovieClip{
			if(_loaders[_clipID]){
				return _loaders[_clipID].content as MovieClip
			} else {
				trace("[ChromeLoader: ] MovieClip by this ID not found!");
				return null;
			}
		}
		
		//Unloads the loaders, clears the static holders
		public function clear():void{
			try{
				_content.splice(0, _content.length);
				 
				 //clean the dictionary, otherwise this may conflict on reload
				for(var i:Number = 0; i< _loaderNames.length; i++){
					delete( _contentNames[_loaderNames[i]] )
				}
				
				//clean the loaders
				for each(var loader:Loader in _loaders){
					//1
					loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);	
					loader.contentLoaderInfo.removeEventListener(IOErrorEvent.NETWORK_ERROR, onError);
					//2
					if (loader.parent) {
						loader.parent.removeChild(loader);
					}
					//3
					if (loader.hasOwnProperty("unloadAndStop")) {      //fp10
						loader.unloadAndStop(true); 
					} else {
						loader.unload();
					}
					
				}
				
			System.gc();
			
			} catch(error:Error){
				trace("[ChromeLoader error on destroy: ] " + error.message);
			}
		}
		
		////	PRIVATE
		
		private function loadContent(_cleanUrl:String):void{			
			_maxTries = 0;			
			var contentLoader:Loader = new Loader();
			contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
			contentLoader.load( new URLRequest( _site + _cleanUrl  ));
			//trace("loading: " + String(_loadersCompleted+1) + " out of " + _loaderNames.length + " | " + _site + _cleanUrl);
		}
		
		private function onComplete(event:Event):void {
			
			_loaders.push(event.target.content.parent as Loader);
			
			_content.push( event.target.content.parent );
			
			_contentNames[String(_loaderNames[_loadersCompleted])] = event.target.content.parent as Loader;
			
			_loadersCompleted ++;
						
			if(_loadersCompleted < _loaderNames.length){
				loadContent(_loaderNames[_loadersCompleted]);
			} else {
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		private function onError(event:Event):void{		
			_maxTries++;
			if(_maxTries < 3){
				var contentLoader:Loader = new Loader();
				contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError, false, 0, true);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError, false, 0, true);	
				contentLoader.load( new URLRequest( _backupUrl + _loaderNames[_loadersCompleted]  ));
				trace("[ERROR] on loading " + _loaderNames[_loadersCompleted] + " .Loading backup file: " + _backupUrl + _loaderNames[_loadersCompleted]);
			} else {
				trace("[ChromeLoader: ] on Error error - max tries reached! Load never completed!");
			}
		}
		
		//// 	PUBLIC STATIC
		
		//returns DisplayObject for given ID (the ID is the index position of the item in the loading names array)
		public static function getContent(_contentID:Number):DisplayObject{
			if(_content[_contentID]){
				return _content[_contentID];
			} else {
				trace("[ChromeLoader: ] Content by this ID not found!");
				return null;
			}
		}
		
		//get content for given name, just pass name from the array you loaded
		public static function getContentByName(_contentName:String):DisplayObject{
			if(_contentNames[_contentName]){
				return _contentNames[_contentName];
			} else {
				trace("[ChromeLoader: ] Content by this NAME not found!");
				return null;
			}
		}
		
	}//end
}

Revision: 54380
at December 23, 2011 20:46 by burnandbass


Updated Code
package  {
	
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.display.Loader;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	
	import flash.utils.Dictionary;
	
	public class ChromeLoader extends EventDispatcher {
		
		private static var _content:Array = [];		
		private static var _contentNames:Dictionary = new Dictionary(true);
		
		private var _loadersCompleted:Number = 0;
		private var _loaders:Array = [];
		private var _loaderNames:Array = [];
		private var _maxTries:Number = 0;
		
		private var _site:String = "";
		private var _backupUrl:String = "";
				
		public function ChromeLoader(site:String = null, backupURL:String = null):void {
			if(site){ _site = site }
			if(backupURL){ _backupUrl = backupURL }
		}
		
		////	PUBLIC
		
		public function loadContents(_items:Array):void{
			for(var i:Number = 0; i< _items.length; i++){
				_loaderNames.push( _items[i] );
			}
			
			loadContent(_loaderNames[_loadersCompleted]);
		}
		
		public function getLoader(_contentID:Number):Loader{
			if(_loaders[_contentID]){
				return _loaders[_contentID];
			} else {
				trace("[ChromeLoader: ] loader by this ID not found!");
				return null;
			}
		}
		
		public function getMovieClip(_clipID:Number):MovieClip{
			if(_loaders[_clipID]){
				return _loaders[_clipID].content as MovieClip
			} else {
				trace("[ChromeLoader: ] MovieClip by this ID not found!");
				return null;
			}
		}
		
		public function clear():void{
			try{
				_content.splice(0, _content.length);
				 
				 //clean the dictionary, otherwise this may conflict on reload
				for(var i:Number = 0; i< _loaderNames.length; i++){
					delete( _contentNames[_loaderNames[i]] )
				}
				
				//clean the loaders
				for each(var loader:Loader in _loaders){
					loader.unloadAndStop(true);
				}
				
			} catch(error:Error){
				trace("[ChromeLoader error on destroy: ] " + error.message);
			}
		}
		
		////	PRIVATE
		
		private function loadContent(_cleanUrl:String):void{
			_maxTries = 0;			
			var contentLoader:Loader = new Loader();
			contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError);	
			trace("Loading: " + _site + _cleanUrl);
			contentLoader.load( new URLRequest( _site + _cleanUrl  ));
		}
		
		private function onComplete(event:Event):void {

			_loaders.push(event.target.content.parent as Loader);
			
			_content.push( event.target.content.parent );
			
			_contentNames[String(_loaderNames[_loadersCompleted])] = event.target.content.parent as Loader;
			
			_loadersCompleted ++;
						
			if(_loadersCompleted < _loaderNames.length){
				loadContent(_loaderNames[_loadersCompleted]);
			} else {
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		private function onError(event:Event):void{		
			_maxTries++;
			if(_maxTries < 3){
				var contentLoader:Loader = new Loader();
				contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError);	
				contentLoader.load( new URLRequest( _backupUrl + _loaderNames[_loadersCompleted]  ));
				trace("[ERROR] on loading " + _loaderNames[_loadersCompleted] + " .Loading backup file: " + _backupUrl + _loaderNames[_loadersCompleted]);
			} else {
				trace("[ChromeLoader: ] on Error error - max tries reached! Load never completed!");
			}
		}
		
		//// 	PUBLIC STATIC
		
		public static function getContent(_contentID:Number):DisplayObject{
			if(_content[_contentID]){
				return _content[_contentID];
			} else {
				trace("[ChromeLoader: ] Content by this ID not found!");
				return null;
			}
		}
		
		public static function getContentByName(_contentName:String):DisplayObject{
			if(_contentNames[_contentName]){
				return _contentNames[_contentName];
			} else {
				trace("[ChromeLoader: ] Content by this NAME not found!");
				return null;
			}
		}
		
	}//end
}

Revision: 54379
at December 21, 2011 23:02 by burnandbass


Initial Code
package  {
	
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	import flash.display.Loader;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	
	
	public class ChromeLoader extends EventDispatcher {
		
		private static var _content:Array = [];		
		
		private var _loadersCompleted:Number = 0;
		private var _loaders:Array = [];
		private var _loaderNames:Array = [];
		private var _maxTries:Number = 0;
				
		private var _site:String = "";
		private var _backupUrl:String = "";
		
		public function ChromeLoader(site:String = null, backupURL:String = null):void {
			if(site){ _site = site }
			if(backupURL){ _backupUrl = backupURL }
		}
		
		////	PUBLIC
		
		public function loadContents(_items:Array):void{
			for(var i:Number = 0; i< _items.length; i++){
				_loaderNames.push( _items[i] );
			}
			
			loadContent(_loaderNames[_loadersCompleted]);
		}
		
		public function getLoader(_contentID:Number):Loader{
			if(_loaders[_contentID]){
				return _loaders[_contentID];
			} else {
				trace("[ChromeLoader: ] loader by this ID not found!");
				return null;
			}
		}
		
		public function getMovieClip(_clipID:Number):MovieClip{
			if(_loaders[_clipID]){
				return _loaders[_clipID].content as MovieClip
			} else {
				trace("[ChromeLoader: ] MovieClip by this ID not found!");
				return null;
			}
		}
		
		public function clear():void{
			try{
				_content.splice(0, _content.length);
				
				for each(var loader:Loader in _loaders){
					loader.unloadAndStop(true);
				}
				
			} catch(error:Error){
				trace("[ChromeLoader error on destroy: ] " + error.message);
			}
		}
		
		////	PRIVATE
		
		private function loadContent(_cleanUrl:String):void{
			_maxTries = 0;
			var contentLoader:Loader = new Loader();
			contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);	
			contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError);	
			trace("Loading: " + _site + _cleanUrl);
			contentLoader.load( new URLRequest( _site + _cleanUrl  ));
		}
		
		private function onComplete(event:Event):void {

			_loaders.push(event.target.content.parent as Loader);
			
			_content.push( event.target.content.parent );
			
			_loadersCompleted ++;
						
			if(_loadersCompleted < _loaderNames.length){
				loadContent(_loaderNames[_loadersCompleted]);
			} else {
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		private function onError(event:Event):void{		
			_maxTries++;
			if(_maxTries < 3){
				var contentLoader:Loader = new Loader();
				contentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);	
				contentLoader.contentLoaderInfo.addEventListener(IOErrorEvent.NETWORK_ERROR, onError);	
				contentLoader.load( new URLRequest( _backupUrl + _loaderNames[_loadersCompleted]  ));
				trace("Loading backup file: " + _backupUrl + _loaderNames[_loadersCompleted]);
			} else {
				trace("[ChromeLoader: ] on Error error - max tries reached! Load never completed!");
			}
		}
		
		//// 	PUBLIC STATIC
		
		public static function getContent(_contentID:Number):DisplayObject{
			if(_content[_contentID]){
				return _content[_contentID];
			} else {
				trace("[ChromeLoader: ] Content by this ID not found!");
				return null;
			}
		}
	
	}//end
}

Initial URL

                                

Initial Description
This is VERY BASIC loading class, the idea is to load array of images and when they're loaded you can retrve them via ChromeLoader.getContent() method, just pass ID. In the constructor you got prepend url (for example images/) and "backup" (example "/backup" ). This will be used if the loader... The names of the functions are self-exaplanary, this is perfect solution for lightwave banners. 
v 1.1 - GarbageCollection added

Initial Title
LightLoader - load array of images, GC, bug fixes, 1.2k compressed

Initial Tags

                                

Initial Language
ActionScript 3