Phaser.Loader = function (game){ this.game = game; this.isLoading = false ; this.hasLoaded = false ; this.progress = 0; this.progressFloat = 0; this.preloadSprite = null ; this.crossOrigin = false ; _AN_Write_baseurl('baseURL', this, false , ''); this.onLoadStart = new Phaser.Signal(); this.onFileStart = new Phaser.Signal(); this.onFileComplete = new Phaser.Signal(); this.onFileError = new Phaser.Signal(); this.onLoadComplete = new Phaser.Signal(); this.onPackComplete = new Phaser.Signal(); this.useXDomainRequest = (this.game.device.ieVersion === 9); this._packList = [] ; this._packIndex = 0; this._fileList = [] ; this._fileIndex = 0; this._progressChunk = 0; this._xhr = new XMLHttpRequest(); this._ajax = null ; } ; Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY = 0; Phaser.Loader.TEXTURE_ATLAS_JSON_HASH = 1; Phaser.Loader.TEXTURE_ATLAS_XML_STARLING = 2; Phaser.Loader.PHYSICS_LIME_CORONA_JSON = 3; Phaser.Loader.PHYSICS_PHASER_JSON = 4; Phaser.Loader.prototype = { setPreloadSprite: function (sprite, direction){ direction = direction || 0; this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, rect: null } ; if (direction === 0) { this.preloadSprite.rect = new Phaser.Rectangle(0, 0, 1, sprite.height); } else { this.preloadSprite.rect = new Phaser.Rectangle(0, 0, sprite.width, 1); } sprite.crop(this.preloadSprite.rect); sprite.visible = true ; } , checkKeyExists: function (type, key){ if (_AN_Read_length('length', this._fileList) > 0) { for (var i = 0; i < _AN_Read_length('length', this._fileList); i++ ){ if (this._fileList[i].type === type && this._fileList[i].key === key) { return true ; } } } return false ; } , getAssetIndex: function (type, key){ if (_AN_Read_length('length', this._fileList) > 0) { for (var i = 0; i < _AN_Read_length('length', this._fileList); i++ ){ if (this._fileList[i].type === type && this._fileList[i].key === key) { return i; } } } return -1; } , getAsset: function (type, key){ if (_AN_Read_length('length', this._fileList) > 0) { for (var i = 0; i < _AN_Read_length('length', this._fileList); i++ ){ if (this._fileList[i].type === type && this._fileList[i].key === key) { return { index: i, file: this._fileList[i]} ; } } } return false ; } , reset: function (){ this.preloadSprite = null ; this.isLoading = false ; this._packList.length = 0; this._packIndex = 0; this._fileList.length = 0; this._fileIndex = 0; } , addToFileList: function (type, key, url, properties){ var entry = { type: type, key: key, url: url, data: null , error: false , loaded: false } ; if (typeof properties !== "undefined") { for (var prop in properties){ entry[prop] = properties[prop]; } } if (this.checkKeyExists(type, key) === false ) { this._fileList.push(entry); } } , replaceInFileList: function (type, key, url, properties){ var entry = { type: type, key: key, url: url, data: null , error: false , loaded: false } ; if (typeof properties !== "undefined") { for (var prop in properties){ entry[prop] = properties[prop]; } } var index = this.getAssetIndex(type, key); if (index === -1) { this._fileList.push(entry); } else { this._fileList[index] = entry; } } , pack: function (key, url, data, callbackContext){ if (typeof url === "undefined") { url = null ; } if (typeof data === "undefined") { data = null ; } if (typeof callbackContext === "undefined") { callbackContext = this; } if (url === null && data === null ) { console.warn('Phaser.Loader.pack - Both url and data are null. One must be set.'); return this; } if (data) { if (typeof data === 'string') { data = JSON.parse(data); } } this._packList.push({ key: key, url: url, data: data, loaded: false , error: false , callbackContext: callbackContext} ); return this; } , image: function (key, url, overwrite){ if (typeof overwrite === "undefined") { overwrite = false ; } if (overwrite) { this.replaceInFileList('image', key, url); } else { this.addToFileList('image', key, url); } return this; } , text: function (key, url, overwrite){ if (typeof overwrite === "undefined") { overwrite = false ; } if (overwrite) { this.replaceInFileList('text', key, url); } else { this.addToFileList('text', key, url); } return this; } , json: function (key, url, overwrite){ if (typeof overwrite === "undefined") { overwrite = false ; } if (overwrite) { this.replaceInFileList('json', key, url); } else { this.addToFileList('json', key, url); } return this; } , xml: function (key, url, overwrite){ if (typeof overwrite === "undefined") { overwrite = false ; } if (overwrite) { this.replaceInFileList('xml', key, url); } else { this.addToFileList('xml', key, url); } return this; } , script: function (key, url, callback, callbackContext){ if (typeof callback === 'undefined') { callback = false ; } if (callback !== false && typeof callbackContext === 'undefined') { callbackContext = callback; } this.addToFileList('script', key, url, { callback: callback, callbackContext: callbackContext} ); return this; } , binary: function (key, url, callback, callbackContext){ if (typeof callback === 'undefined') { callback = false ; } if (callback !== false && typeof callbackContext === 'undefined') { callbackContext = callback; } this.addToFileList('binary', key, url, { callback: callback, callbackContext: callbackContext} ); return this; } , spritesheet: function (key, url, frameWidth, frameHeight, frameMax, margin, spacing){ if (typeof frameMax === "undefined") { frameMax = -1; } if (typeof margin === "undefined") { margin = 0; } if (typeof spacing === "undefined") { spacing = 0; } this.addToFileList('spritesheet', key, url, { frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax, margin: margin, spacing: spacing} ); return this; } , audio: function (key, urls, autoDecode){ if (typeof autoDecode === "undefined") { autoDecode = true ; } this.addToFileList('audio', key, urls, { buffer: null , autoDecode: autoDecode} ); return this; } , audiosprite: function (key, urls, atlasURL){ this.audio(key, urls); this.json(key + '-audioatlas', atlasURL); return this; } , tilemap: function (key, url, data, format){ if (typeof url === "undefined") { url = null ; } if (typeof data === "undefined") { data = null ; } if (typeof format === "undefined") { format = Phaser.Tilemap.CSV; } if (url == null && data == null ) { console.warn('Phaser.Loader.tilemap - Both url and data are null. One must be set.'); return this; } if (data) { switch (format){ case Phaser.Tilemap.CSV: break ; case Phaser.Tilemap.TILED_JSON: if (typeof data === 'string') { data = JSON.parse(data); } break ; } this.game.cache.addTilemap(key, null , data, format); } else { this.addToFileList('tilemap', key, url, { format: format} ); } return this; } , physics: function (key, url, data, format){ if (typeof url === "undefined") { url = null ; } if (typeof data === "undefined") { data = null ; } if (typeof format === "undefined") { format = Phaser.Physics.LIME_CORONA_JSON; } if (url == null && data == null ) { console.warn('Phaser.Loader.physics - Both url and data are null. One must be set.'); return this; } if (data) { if (typeof data === 'string') { data = JSON.parse(data); } this.game.cache.addPhysicsData(key, null , data, format); } else { this.addToFileList('physics', key, url, { format: format} ); } return this; } , bitmapFont: function (key, textureURL, xmlURL, xmlData, xSpacing, ySpacing){ if (typeof xmlURL === "undefined") { xmlURL = null ; } if (typeof xmlData === "undefined") { xmlData = null ; } if (typeof xSpacing === "undefined") { xSpacing = 0; } if (typeof ySpacing === "undefined") { ySpacing = 0; } if (xmlURL) { this.addToFileList('bitmapfont', key, textureURL, { xmlURL: xmlURL, xSpacing: xSpacing, ySpacing: ySpacing} ); } else { if (typeof xmlData === 'string') { var xml; try { if (window.DOMParser) { var domparser = new DOMParser(); xml = domparser.parseFromString(xmlData, "text/xml"); } else { xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = 'false'; xml.loadXML(xmlData); } } catch (e) { xml = undefined; } if (!xml || !xml.documentElement || _AN_Read_length('length', _AN_Call_getelementsbytagname('getElementsByTagName', xml, "parsererror"))) { throw new Error("Phaser.Loader. Invalid Bitmap Font XML given") } else { this.addToFileList('bitmapfont', key, textureURL, { xmlURL: null , xmlData: xml, xSpacing: xSpacing, ySpacing: ySpacing} ); } } } return this; } , atlasJSONArray: function (key, textureURL, atlasURL, atlasData){ return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY); } , atlasJSONHash: function (key, textureURL, atlasURL, atlasData){ return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_HASH); } , atlasXML: function (key, textureURL, atlasURL, atlasData){ return this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING); } , atlas: function (key, textureURL, atlasURL, atlasData, format){ if (typeof atlasURL === "undefined") { atlasURL = null ; } if (typeof atlasData === "undefined") { atlasData = null ; } if (typeof format === "undefined") { format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY; } if (atlasURL) { this.addToFileList('textureatlas', key, textureURL, { atlasURL: atlasURL, format: format} ); } else { switch (format){ case Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY: if (typeof atlasData === 'string') { atlasData = JSON.parse(atlasData); } break ; case Phaser.Loader.TEXTURE_ATLAS_XML_STARLING: if (typeof atlasData === 'string') { var xml; try { if (window.DOMParser) { var domparser = new DOMParser(); xml = domparser.parseFromString(atlasData, "text/xml"); } else { xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = 'false'; xml.loadXML(atlasData); } } catch (e) { xml = undefined; } if (!xml || !xml.documentElement || _AN_Read_length('length', _AN_Call_getelementsbytagname('getElementsByTagName', xml, "parsererror"))) { throw new Error("Phaser.Loader. Invalid Texture Atlas XML given") } else { atlasData = xml; } } break ; } this.addToFileList('textureatlas', key, textureURL, { atlasURL: null , atlasData: atlasData, format: format} ); } return this; } , removeFile: function (type, key){ var file = this.getAsset(type, key); if (file !== false ) { this._fileList.splice(file.index, 1); } } , removeAll: function (){ this._fileList.length = 0; } , start: function (){ if (this.isLoading) { return ; } if (_AN_Read_length('length', this._packList) > 0) { this._packIndex = 0; this.loadPack(); } else { this.beginLoad(); } } , beginLoad: function (){ this.progress = 0; this.progressFloat = 0; this.hasLoaded = false ; this.isLoading = true ; this.onLoadStart.dispatch(_AN_Read_length('length', this._fileList)); if (_AN_Read_length('length', this._fileList) > 0) { this._fileIndex = 0; this._progressChunk = 100 / _AN_Read_length('length', this._fileList); this.loadFile(); } else { this.progress = 100; this.progressFloat = 100; this.hasLoaded = true ; this.isLoading = false ; this.onLoadComplete.dispatch(); } } , loadPack: function (){ if (!this._packList[this._packIndex]) { console.warn('Phaser.Loader loadPackList invalid index ' + this._packIndex); return ; } var pack = this._packList[this._packIndex]; if (pack.data !== null ) { this.packLoadComplete(this._packIndex, false ); } else { this.xhrLoad(this._packIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', pack), 'text', 'packLoadComplete', 'packLoadError'); } } , packLoadComplete: function (index, parse){ if (typeof parse === 'undefined') { parse = true ; } if (!this._packList[index]) { console.warn('Phaser.Loader packLoadComplete invalid index ' + index); return ; } var pack = this._packList[index]; pack.loaded = true ; if (parse) { var data = JSON.parse(this._xhr.responseText); } else { var data = this._packList[index].data; } if (data[pack.key]) { var file; for (var i = 0; i < _AN_Read_length('length', data[pack.key]); i++ ){ file = data[pack.key][i]; switch (file.type){ case "image": this.image(file.key, _AN_Read_url("url", file), file.overwrite); break ; case "text": this.text(file.key, _AN_Read_url("url", file), file.overwrite); break ; case "json": this.json(file.key, _AN_Read_url("url", file), file.overwrite); break ; case "xml": this.xml(file.key, _AN_Read_url("url", file), file.overwrite); break ; case "script": this.script(file.key, _AN_Read_url("url", file), file.callback, pack.callbackContext); break ; case "binary": this.binary(file.key, _AN_Read_url("url", file), file.callback, pack.callbackContext); break ; case "spritesheet": this.spritesheet(file.key, _AN_Read_url("url", file), file.frameWidth, file.frameHeight, file.frameMax, file.margin, file.spacing); break ; case "audio": this.audio(file.key, file.urls, file.autoDecode); break ; case "tilemap": this.tilemap(file.key, _AN_Read_url("url", file), file.data, Phaser.Tilemap[file.format]); break ; case "physics": this.physics(file.key, _AN_Read_url("url", file), file.data, Phaser.Loader[file.format]); break ; case "bitmapFont": this.bitmapFont(file.key, file.textureURL, file.xmlURL, file.xmlData, file.xSpacing, file.ySpacing); break ; case "atlasJSONArray": this.atlasJSONArray(file.key, file.textureURL, file.atlasURL, file.atlasData); break ; case "atlasJSONHash": this.atlasJSONHash(file.key, file.textureURL, file.atlasURL, file.atlasData); break ; case "atlasXML": this.atlasXML(file.key, file.textureURL, file.atlasURL, file.atlasData); break ; case "atlas": this.atlas(file.key, file.textureURL, file.atlasURL, file.atlasData, Phaser.Loader[file.format]); break ; } } } this.nextPack(index, true ); } , packError: function (index){ this._packList[index].loaded = true ; this._packList[index].error = true ; this.onFileError.dispatch(this._packList[index].key, this._packList[index]); console.warn("Phaser.Loader error loading pack file: " + this._packList[index].key + ' from URL ' + _AN_Read_url('url', this._packList[index])); this.nextPack(index, false ); } , nextPack: function (index, success){ this.onPackComplete.dispatch(this._packList[index].key, success, this.totalLoadedPacks(), _AN_Read_length('length', this._packList)); this._packIndex++ ; if (this._packIndex < _AN_Read_length('length', this._packList)) { this.loadPack(); } else { this.beginLoad(); } } , loadFile: function (){ if (!this._fileList[this._fileIndex]) { console.warn('Phaser.Loader loadFile invalid index ' + this._fileIndex); return ; } var file = this._fileList[this._fileIndex]; var _this = this; this.onFileStart.dispatch(this.progress, file.key, _AN_Read_url('url', file)); switch (file.type){ case 'image': case 'spritesheet': case 'textureatlas': case 'bitmapfont': file.data = new Image(); file.data.name = file.key; file.data.onload = function (){ return _this.fileComplete(_this._fileIndex); } ; file.data.onerror = function (){ return _this.fileError(_this._fileIndex); } ; if (this.crossOrigin) { file.data.crossOrigin = this.crossOrigin; } _AN_Write_src('src', file.data, false , _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file)); break ; case 'audio': _AN_Write_url('url', file, false , this.getAudioURL(_AN_Read_url('url', file))); if (_AN_Read_url('url', file) !== null ) { if (this.game.sound.usingWebAudio) { this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), 'arraybuffer', 'fileComplete', 'fileError'); } else if (this.game.sound.usingAudioTag) { if (this.game.sound.touchLocked) { file.data = new Audio(); file.data.name = file.key; file.data.preload = 'auto'; _AN_Write_src('src', file.data, false , _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file)); this.fileComplete(this._fileIndex); } else { file.data = new Audio(); file.data.name = file.key; file.data.onerror = function (){ return _this.fileError(_this._fileIndex); } ; file.data.preload = 'auto'; _AN_Write_src('src', file.data, false , _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file)); file.data.addEventListener('canplaythrough', function (){ Phaser.GAMES[_this.game.id].load.fileComplete(_this._fileIndex); } , false ); _AN_Call_load('load', file.data); } } } else { this.fileError(this._fileIndex); } break ; case 'json': if (this.useXDomainRequest && window.XDomainRequest) { this._ajax = new window.XDomainRequest(); this._ajax.timeout = 3000; this._ajax.onerror = function (){ return _this.dataLoadError(_this._fileIndex); } ; this._ajax.ontimeout = function (){ return _this.dataLoadError(_this._fileIndex); } ; this._ajax.onprogress = function (){ } ; this._ajax.onload = function (){ return _this.jsonLoadComplete(_this._fileIndex); } ; _AN_Call_open('open', this._ajax, 'GET', _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), true ); _AN_Call_settimeout('setTimeout', window, function (){ _AN_Call_send('send', this._ajax); } , 0); } else { this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), 'text', 'jsonLoadComplete', 'dataLoadError'); } break ; case 'xml': this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), 'text', 'xmlLoadComplete', 'dataLoadError'); break ; case 'tilemap': if (file.format === Phaser.Tilemap.TILED_JSON) { this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), 'text', 'jsonLoadComplete', 'dataLoadError'); } else if (file.format === Phaser.Tilemap.CSV) { this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), 'text', 'csvLoadComplete', 'dataLoadError'); } else { throw new Error("Phaser.Loader. Invalid Tilemap format: " + file.format) } break ; case 'text': case 'script': case 'physics': this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), 'text', 'fileComplete', 'fileError'); break ; case 'binary': this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + _AN_Read_url('url', file), 'arraybuffer', 'fileComplete', 'fileError'); break ; } } , xhrLoad: function (index, url, type, onload, onerror){ _AN_Call_open('open', this._xhr, "GET", url, true ); this._xhr.responseType = type; var _this = this; this._xhr.onload = function (){ return _this[onload](index); } ; this._xhr.onerror = function (){ return _this[onerror](index); } ; _AN_Call_send("send", this._xhr); } , getAudioURL: function (urls){ var extension; if (typeof urls === 'string') { urls = [urls] ; } for (var i = 0; i < _AN_Read_length('length', urls); i++ ){ extension = urls[i].toLowerCase(); extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1); if (this.game.device.canPlayAudio(extension)) { return urls[i]; } } return null ; } , fileError: function (index){ this._fileList[index].loaded = true ; this._fileList[index].error = true ; this.onFileError.dispatch(this._fileList[index].key, this._fileList[index]); console.warn("Phaser.Loader error loading file: " + this._fileList[index].key + ' from URL ' + _AN_Read_url('url', this._fileList[index])); this.nextFile(index, false ); } , fileComplete: function (index){ if (!this._fileList[index]) { console.warn('Phaser.Loader fileComplete invalid index ' + index); return ; } var file = this._fileList[index]; file.loaded = true ; var loadNext = true ; switch (file.type){ case 'image': this.game.cache.addImage(file.key, _AN_Read_url('url', file), file.data); break ; case 'spritesheet': this.game.cache.addSpriteSheet(file.key, _AN_Read_url('url', file), file.data, file.frameWidth, file.frameHeight, file.frameMax, file.margin, file.spacing); break ; case 'textureatlas': if (file.atlasURL == null ) { this.game.cache.addTextureAtlas(file.key, _AN_Read_url('url', file), file.data, file.atlasData, file.format); } else { loadNext = false ; if (file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY || file.format == Phaser.Loader.TEXTURE_ATLAS_JSON_HASH) { this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + file.atlasURL, 'text', 'jsonLoadComplete', 'dataLoadError'); } else if (file.format == Phaser.Loader.TEXTURE_ATLAS_XML_STARLING) { this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + file.atlasURL, 'text', 'xmlLoadComplete', 'dataLoadError'); } else { throw new Error("Phaser.Loader. Invalid Texture Atlas format: " + file.format) } } break ; case 'bitmapfont': if (file.xmlURL == null ) { this.game.cache.addBitmapFont(file.key, _AN_Read_url('url', file), file.data, file.xmlData, file.xSpacing, file.ySpacing); } else { loadNext = false ; this.xhrLoad(this._fileIndex, _AN_Read_baseurl('baseURL', this) + file.xmlURL, 'text', 'xmlLoadComplete', 'dataLoadError'); } break ; case 'audio': if (this.game.sound.usingWebAudio) { file.data = this._xhr.response; this.game.cache.addSound(file.key, _AN_Read_url('url', file), file.data, true , false ); if (file.autoDecode) { var that = this; var key = file.key; this.game.cache.updateSound(key, 'isDecoding', true ); this.game.sound.context.decodeAudioData(file.data, function (buffer){ if (buffer) { that.game.cache.decodedSound(key, buffer); that.game.sound.onSoundDecode.dispatch(key, that.game.cache.getSound(key)); } } ); } } else { file.data.removeEventListener('canplaythrough', Phaser.GAMES[this.game.id].load.fileComplete); this.game.cache.addSound(file.key, _AN_Read_url('url', file), file.data, false , true ); } break ; case 'text': file.data = this._xhr.responseText; this.game.cache.addText(file.key, _AN_Read_url('url', file), file.data); break ; case 'physics': var data = JSON.parse(this._xhr.responseText); this.game.cache.addPhysicsData(file.key, _AN_Read_url('url', file), data, file.format); break ; case 'script': file.data = _AN_Call_createelement('createElement', document, 'script'); file.data.language = 'javascript'; file.data.type = 'text/javascript'; file.data.defer = false ; _AN_Write_text('text', file.data, false , this._xhr.responseText); _AN_Call_appendchild('appendChild', document.head, file.data); if (file.callback) { file.data = file.callback.call(file.callbackContext, file.key, this._xhr.responseText); } break ; case 'binary': if (file.callback) { file.data = file.callback.call(file.callbackContext, file.key, this._xhr.response); } else { file.data = this._xhr.response; } this.game.cache.addBinary(file.key, file.data); break ; } if (loadNext) { this.nextFile(index, true ); } } , jsonLoadComplete: function (index){ if (!this._fileList[index]) { console.warn('Phaser.Loader jsonLoadComplete invalid index ' + index); return ; } var file = this._fileList[index]; if (this._ajax && this._ajax.responseText) { var data = JSON.parse(this._ajax.responseText); } else { var data = JSON.parse(this._xhr.responseText); } file.loaded = true ; if (file.type === 'tilemap') { this.game.cache.addTilemap(file.key, _AN_Read_url('url', file), data, file.format); } else if (file.type === 'json') { this.game.cache.addJSON(file.key, _AN_Read_url('url', file), data); } else { this.game.cache.addTextureAtlas(file.key, _AN_Read_url('url', file), file.data, data, file.format); } this.nextFile(index, true ); } , csvLoadComplete: function (index){ if (!this._fileList[index]) { console.warn('Phaser.Loader csvLoadComplete invalid index ' + index); return ; } var file = this._fileList[index]; var data = this._xhr.responseText; file.loaded = true ; this.game.cache.addTilemap(file.key, _AN_Read_url('url', file), data, file.format); this.nextFile(index, true ); } , dataLoadError: function (index){ var file = this._fileList[index]; file.loaded = true ; file.error = true ; console.warn("Phaser.Loader dataLoadError: " + file.key); this.nextFile(index, true ); } , xmlLoadComplete: function (index){ if (this._xhr.responseType !== '' && this._xhr.responseType !== 'text') { console.warn('Invalid XML Response Type', this._fileList[index]); console.warn(this._xhr); } var data = this._xhr.responseText; var xml; try { if (window.DOMParser) { var domparser = new DOMParser(); xml = domparser.parseFromString(data, "text/xml"); } else { xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = 'false'; xml.loadXML(data); } } catch (e) { xml = undefined; } if (!xml || !xml.documentElement || _AN_Read_length('length', _AN_Call_getelementsbytagname('getElementsByTagName', xml, "parsererror"))) { throw new Error("Phaser.Loader. Invalid XML given") } var file = this._fileList[index]; file.loaded = true ; if (file.type === 'bitmapfont') { this.game.cache.addBitmapFont(file.key, _AN_Read_url('url', file), file.data, xml, file.xSpacing, file.ySpacing); } else if (file.type === 'textureatlas') { this.game.cache.addTextureAtlas(file.key, _AN_Read_url('url', file), file.data, xml, file.format); } else if (file.type === 'xml') { this.game.cache.addXML(file.key, _AN_Read_url('url', file), xml); } this.nextFile(index, true ); } , nextFile: function (previousIndex, success){ this.progressFloat += this._progressChunk; this.progress = Math.round(this.progressFloat); if (this.progress > 100) { this.progress = 100; } if (this.preloadSprite !== null ) { if (this.preloadSprite.direction === 0) { this.preloadSprite.rect.width = Math.floor((this.preloadSprite.width / 100) * this.progress); } else { this.preloadSprite.rect.height = Math.floor((this.preloadSprite.height / 100) * this.progress); } this.preloadSprite.sprite.updateCrop(); } this.onFileComplete.dispatch(this.progress, this._fileList[previousIndex].key, success, this.totalLoadedFiles(), _AN_Read_length('length', this._fileList)); if (this.totalQueuedFiles() > 0) { this._fileIndex++ ; this.loadFile(); } else { this.hasLoaded = true ; this.isLoading = false ; this.removeAll(); this.onLoadComplete.dispatch(); } } , totalLoadedFiles: function (){ var total = 0; for (var i = 0; i < _AN_Read_length('length', this._fileList); i++ ){ if (this._fileList[i].loaded) { total++ ; } } return total; } , totalQueuedFiles: function (){ var total = 0; for (var i = 0; i < _AN_Read_length('length', this._fileList); i++ ){ if (this._fileList[i].loaded === false ) { total++ ; } } return total; } , totalLoadedPacks: function (){ var total = 0; for (var i = 0; i < _AN_Read_length('length', this._packList); i++ ){ if (this._packList[i].loaded) { total++ ; } } return total; } , totalQueuedPacks: function (){ var total = 0; for (var i = 0; i < _AN_Read_length('length', this._packList); i++ ){ if (this._packList[i].loaded === false ) { total++ ; } } return total; } } ; Phaser.Loader.prototype.constructor = Phaser.Loader;