javascripthtmlcreatejssoundjs

CreateJS - Type not recognized error thrown during sound registration


I am trying to load sounds through the SoundJS sound registration, and getting the following error:

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

I figure that the soundjs library is having issues either locating my files or having trouble with the file extensions, but I am using .ogg, which is inline with all the examples I've seen.

Here is my code:

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 is an array of objects with a source item giving the path to the .ogg files, and an id. I've double and triple checked the path names, so pretty sure that's not it. Any ideas? I am developing on Chrome.


Solution

  • Thanks for posting a github link. It was helpful. Fortunately, I have a super simple answer for you.

    Rename the "Object" class you made in Main.js, and you should be good to go.

    -- The long answer --

    I tossed a breakpoint the error that is thrown, and it showed that when SoundJS tries to create a LoadItem, it fails. This is because it should be treating the LoadItem it receives as an Object, but the line below is failing:

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

    At first I thought there was a bug in SoundJS that we had somehow missed in the last 2 years, but closer inspection showed that object prototypes in your application are messed up. If you open any browser window, and hit the console, this will return true:

    ({}) instanceof Object
    // true
    

    However while running your app, it returns false.

    The issue became clear when I removed all your other classes other than CreateJS and main, and then tried this:

    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 :)