package $(PackageName)$(CSLB){
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.utils.getDefinitionByName;
	
	/**
	$(CBI)* ...
	$(CBI)* @author $(DefaultUser)
	$(CBI)*/
	public class Preloader extends MovieClip $(CSLB){
		
		public function Preloader() $(CSLB){
			if (stage) {
				stage.scaleMode = StageScaleMode.NO_SCALE;
				stage.align = StageAlign.TOP_LEFT;
			}
			addEventListener(Event.ENTER_FRAME, checkFrame);
			loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
			loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
			
			// TODO show loader
		}
		
		private function ioError(e:IOErrorEvent):void $(CSLB){
			trace(e.text);
		}
		
		private function progress(e:ProgressEvent):void $(CSLB){
			// TODO update loader
		}
		
		private function checkFrame(e:Event):void $(CSLB){
			if (currentFrame == totalFrames) $(CSLB){
				stop();
				loadingFinished();
			}
		}
		
		private function loadingFinished():void $(CSLB){
			removeEventListener(Event.ENTER_FRAME, checkFrame);
			loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
			loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
			
			// TODO hide loader
			
			startup();
		}
		
		private function startup():void $(CSLB){
			var mainClass:Class = getDefinitionByName("$(PackageDot)Main") as Class;
			addChild(new mainClass() as DisplayObject);
		}
		
	}
	
}