// Class: openfl.display.Preloader

var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this

$global.Object.defineProperty(exports, "__esModule", {value: true});

var __map_reserved = {};

// Imports

var $hxClasses = require("./../../hxClasses_stub").default;
var $import = require("./../../import_stub").default;
var $bind = require("./../../bind_stub").default;
var $extend = require("./../../extend_stub").default;
function lime_app_Preloader() {return require("./../../lime/app/Preloader");}
function openfl_Lib() {return require("./../../openfl/Lib");}
function openfl_events_Event() {return require("./../../openfl/events/Event");}
function openfl_events_ProgressEvent() {return require("./../../openfl/events/ProgressEvent");}

// Constructor

var Preloader = function(display) {
	(lime_app_Preloader().default).call(this);
	this.display = display;
	if(display != null) {
		display.addEventListener("unload",$bind(this,this.display_onUnload));
		(openfl_Lib().default).get_current().addChild(display);
	}
}

// Meta

Preloader.__name__ = ["openfl","display","Preloader"];
Preloader.__super__ = (lime_app_Preloader().default);
Preloader.prototype = $extend((lime_app_Preloader().default).prototype, {
	start: function() {
		if(this.simulateProgress) {
			return;
		}
		this.ready = true;
		(openfl_Lib().default).get_current().get_loaderInfo().__complete();
		if(this.display != null) {
			var complete = new (openfl_events_Event().default)("complete",true,true);
			this.display.dispatchEvent(complete);
			if(!complete.isDefaultPrevented()) {
				this.display.dispatchEvent(new (openfl_events_Event().default)("unload"));
			}
		} else {
			(lime_app_Preloader().default).prototype.start.call(this);
		}
	},
	update: function(loaded,total) {
		(openfl_Lib().default).get_current().get_loaderInfo().__update(loaded,total);
		if(this.display != null) {
			this.display.dispatchEvent(new (openfl_events_ProgressEvent().default)("progress",true,true,loaded,total));
		}
	},
	display_onUnload: function(event) {
		if(this.display != null) {
			this.display.removeEventListener("unload",$bind(this,this.display_onUnload));
			if(this.display.parent == (openfl_Lib().default).get_current()) {
				(openfl_Lib().default).get_current().removeChild(this.display);
			}
			(openfl_Lib().default).get_current().stage.set_focus(null);
			this.display = null;
		}
		if(this.ready && !this.simulateProgress) {
			(lime_app_Preloader().default).prototype.start.call(this);
		}
	}
});
Preloader.prototype.__class__ = $hxClasses["openfl.display.Preloader"] = Preloader;

// Init



// Statics




// Export

exports.default = Preloader;