因此,在加载 fileList 数组中的第一个文件时正确调用的函数 fileLoaded 中,它尝试调用 this.loadAnother() 但 Firefox 坚持:
TypeError: this.loadAnother is not a function
为什么它坚持它不是一个功能?它从 loadProjectSource() 中被正确调用,但试图加载下一个文件,它不是一个函数。此外,调试“this”会产生奇怪的结果,这让我相信这是罪魁祸首。我不是 Javascript 专家,但我从未见过这种行为。它与类创建有关吗?如果是这样,为什么 loadProjectSource() 的第一次调用有效?
var ScriptLoader = Class.extend({ // Want to add functionality to this to allow PHP or inline loading...perhaps later
init: function () {
this.totalEngineToLoad = 0;
this.totalEntitiesToLoad = 0;
this.totalScenesToLoad = 0;
this.totalLoaded = 0;
this.entitiesToLoad = [0, 0, 0];
this.fileList = ['./js/engine/Entity.js', './js/engine/Scene.js'];
this.preload;
},
loadProjectSource: function (directory) {
if(this.preload != null) {
this.preload.close();
}
this.preload = new createjs.LoadQueue();
this.preload.addEventListener("fileload", this.fileLoaded);
this.preload.addEventListener("error", this.fileError);
this.preload.setMaxConnections(5);
this.loadAnother();
},
loadAnother: function () {
var myItem = this.fileList.shift();
if(this.fileList.length != 0) {
this.preload.loadFile(myItem);
}
},
fileLoaded: function (e) {
debug('Loaded ' + e.item.src);
debug(this.fileList);
},
fileError: function (e) {
debug('Error ' + e.item.src);
}
}