0

我正在尝试通过 SoundJS 声音注册加载声音,并收到以下错误:

createjs.js:15 Uncaught Error: Type not recognized.

我认为 soundjs 库在定位我的文件或文件扩展名方面存在问题,但我使用的是 .ogg,它与我见过的所有示例都是内联的。

这是我的代码:

createjs.Sound.alternateExtensions = ["mp3", "ogg"];

createjs.Sound.on("fileload", function(event) {
    console.log(event);
}, this);

for (var i = 0; i < soundManifest.length; i++) {
    soundManifest[i].loaded = false;
    console.log("loading " + soundManifest[i].src);
    createjs.Sound.registerSound(soundManifest[i].src, soundManifest[i].id)
}

soundManifest 是一个对象数组,其中一个源项给出了 .ogg 文件的路径和一个 id。我已经两次和三次检查了路径名,所以很确定不是这样。有任何想法吗?我正在 Chrome 上开发。

4

1 回答 1

3

感谢您发布 github 链接。这很有帮助。幸运的是,我有一个超级简单的答案给你。

重命名您在 Main.js 中创建的“对象”类,您应该一切顺利。

——长答案——

我在抛出的错误中抛出了一个断点,它表明当 SoundJS 尝试创建一个 LoadItem 时,它失败了。这是因为它应该将接收到的 LoadItem 视为对象,但下面的行失败了:

} else if (value instanceof Object && value.src) {
    // This code should be executed
}

起初,我认为 SoundJS 中有一个错误,我们在过去 2 年中不知何故错过了,但仔细检查表明,您的应用程序中的对象原型搞砸了。如果您打开任何浏览器窗口,然后点击控制台,这将返回true

({}) instanceof Object
// true

但是,在运行您的应用程序时,它会返回false.

当我删除除 CreateJS 和 main 之外的所有其他类时,问题变得清晰,然后尝试了这个:

new Object();
// Throws an error that includes info about "Victor"

In main.js, you are defining an "Object" class, which extends a CreateJS Shape. It is global because there is no method closure around the code, so it overwrites the global Object class/prototype.


The reason I included this explanation, is because I couldn't figure out what was going on until I had my steps to show that prototypes were broken in the app mostly written out before the reason dawned on me. I thought it might be of some interest :)

于 2016-04-19T22:09:45.157 回答