在一个小型引擎上运行我的HTML5测试游戏,将它用作深入Javascript并在同一时间玩得开心的好方法。成功,顺便说一句。预加载JavaScript文件
但是,我刚刚发现这个很酷的小脚本,名为PreloadJS(http://www.createjs.com/#!/PreloadJS)。还使用John Resig的经典继承类JS。非常酷,享受它。我试图用PreloadJS在我所有的引擎文件拉...但我似乎有一个问题。下面是我使用的代码(保持简单的目的):
var ScriptLoader = Class.extend({ // Want to add functionality to this to allow PHP or inline loading...perhaps later
init: function() {
this.fileList = [
'Empty.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 item = this.fileList.shift();
if(this.fileList.length != 0) {
this.preload.loadFile(item);
}
},
fileLoaded: function(e) {
debug('Loaded ' + e.item.src);
this.loadAnother();
},
fileError: function(e) {
debug('Error ' + e.item.src);
}
}
从我的引擎实例,我打电话ScriptLoader.loadProjectSource。它做什么,但引发错误,并在错误的文档处理(和一般的加载JS文件...)是在PreloadJS现场非常稀疏。它着重于预加载图像(不可否认,这看起来很棒)。无论如何,所以是的,这是抛出错误。它不能是文件,当我试着加载一个完全空白的JS文件(因为你可以看到)。仍然在Empty.js文件上抛出一个错误。
懊恼:)提前致谢。