ActionScript3 Clase Loaders
22/11/2007
ActionScript 3 great progress compared to ActionScript 2, One of the things that are much improved is the content of external load using the class Loader

I developed a class, call Loaders, that use Loader of Flash Player to facilitate the use of this and add new features reusable

So using Loaders:
import phoxer.Loaders;
 
var ld:Loaders= new Loaders();<br>
ld.backProgress=onProgress; 
ld.backComplete=onComplete;
ld.cancelar=true;
ld.useUnloadAndStop=true;
 
function onProgress(num:Number):void{
	//aqui se puede leer el progreso de la carga
}
function onComplete(ob:Object,ld:Loader):void{
	//aqui recivimos dos parametros
	//ob: el objeto que contiene el loader.
	//ld: el objeto loader.
}
 
//Asi se cargan los contenidos
ld.setLoad(this,"contenido_externo.swf");
 


So is the easy management of my class to load external content, it serves both to swf, to jpg,gif and png.


It also has other features such as:

-ld.useUnloadAndStop: Enable the use of UnloadAndStop
-ld.backProgress Used to return the progress of the load
-ld.backComplete Used to return when load is complete
-ld.cancelar Enable de unload() and close() of the Loader.

My class Loaders:
/**
LOADER by .:[PHOXER]:.
http://www.phoxer.com
v 4.4; 
*/
package phoxer{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	public class Loaders{
		private var clip:Object;
		private var loader:Loader;
		private var fileurl:URLRequest;
		private var isLoading:Boolean=false;
		public var backInit:Function=null;
		public var backProgress:Function=null;
		public var backComplete:Function=null;
		public var backError:Function=null;
		public var cancelar:Boolean=false;
		public var isVisible:Boolean=true;
		public var useUnloadAndStop:Boolean=false;
		public var useGarbageColector:Boolean=true;
		public function setLoad(cont:Object,url:String,nx:int=0,ny:int=0):void{
			clip=cont;
			//opts
			if(cancelar){
				if(isLoading){
					cancelLoad();
				}
			}
 
			loader = new Loader();
			fileurl = new URLRequest(url);
 
			loader.load(fileurl);
	        loader.x=nx;
			loader.y=ny;
			loader.visible=isVisible;
 
			configurarListeners(loader.contentLoaderInfo);
			clip.addChild(loader);
			isLoading=true;
		}
		public function cancelLoad():void {
			if (isLoading) {
				isLoading=false;
				loader.close();
				unload();
			}
		}
		public function removeLoader():void{
			if(loader!=null && !isLoading){
				unload();
			}
		}
 
		private function unload():void{
			if(useUnloadAndStop){
				try { 
	            	loader.unloadAndStop(useGarbageColector);
	         	} catch (e:Error) { 
	            	loader.unload(); 
	         	} 
  			}else{
  				loader.unload();
  			}
		}
 
		public function loading():Boolean{
			return isLoading;
		}
 
		private function configurarListeners(evnt:IEventDispatcher):void {
			if (backInit!=null) {
				evnt.addEventListener(Event.OPEN, onStart,false,0,true);
			}
			if (backProgress!=null) {
				evnt.addEventListener(ProgressEvent.PROGRESS, onProgress,false,0,true);
			}
			if(backComplete!=null){
				evnt.addEventListener(Event.COMPLETE, onComplete,false,0,true);
			}
			evnt.addEventListener(IOErrorEvent.IO_ERROR, onError,false,0,true);
		}
		private function onStart(e:Event):void {
				backInit();
		}
		private function onProgress(e:ProgressEvent):void {
			var total:Number = Math.round((e.bytesLoaded*100)/e.bytesTotal);
			backProgress(total);
		}
		private function onComplete(e:Event):void {
			isLoading=false;
			backComplete(loader.getChildAt(0),loader);
		}
		private function onError(e:Event):void {
			trace("LOADER ERROR: "+e)
			isLoading=false;
			if(backError!=null){
				backError();
			}
		}
	}
}


| ActionScript 3 | Flash CS3 | Flash CS4
Share |


No hay comentarios.

Canal Rss

Donar al blog de tutoriales de Phoxer.

----------------------------------------------


Si los tutoriales o los temas tratados en este blog te gustaron y quieres ayudarme a mantenerlos en linea puede hacer una donacion.
La donaciones son destinadas para mantener este blog y a los tutoriales Online.

Donar al blog de tutoriales de Phoxer.

Phoxer