JavaScript error with Adobe Edge Commons library

Hey everyone, I’m having trouble with the Adobe Edge Commons library. I’m trying to set up some audio for my project, but I’m running into an error on Chrome and IE10. It says ‘Uncaught ReferenceError: EC is not defined’. Oddly enough, it works fine on Firefox.

Here’s a simplified version of what I’m trying to do:

function setupAudio() {
  const audioPath = 'audio/';
  AudioManager.init(
    [
      {file: audioPath + 'welcome.mp3', name: 'welcome'}
    ],
    () => console.log('Audio setup complete')
  );
}

loadScript({
  src: 'lib/audio-manager.js',
  onLoad: () => {
    if (typeof AudioManager === 'undefined') {
      loadScript({src: 'lib/audio-manager.js', onLoad: setupAudio});
    } else {
      setupAudio();
    }
  }
});

Any ideas on why this might be happening? I’ve double-checked the file paths and everything seems correct. Thanks in advance for any help!

hey Alice45, sounds like a tricky issue! have u checked if the EC object is properly loaded before using it? maybe try wrapping ur code in a DOMContentLoaded event listener or use a script loader like RequireJS to ensure all dependencies are loaded. also, double-check if the Edge Commons library is included correctly in ur HTML. good luck!

I’ve dealt with similar EC-related issues in the past. One thing that often gets overlooked is browser caching. Try clearing your browser cache or using incognito mode to rule that out. Also, check your browser’s console for any other errors that might be blocking the script from loading properly.

Another approach you could consider is using a more modern audio library like Howler.js. It’s lightweight, has great browser support, and handles a lot of the cross-browser inconsistencies for you. I switched to it for a recent project and it made audio implementation much smoother.

If you’re set on using Edge Commons, make sure you’re not mixing async and sync script loading methods. Sometimes that can cause race conditions where scripts don’t load in the expected order. Consider using a script loader like LABjs or HeadJS for more control over script loading order.

I’ve encountered similar issues with the Adobe Edge Commons library before. One potential solution is to ensure that the library is fully loaded before executing your code. You might want to try adding a small delay or using a callback function after loading the library.

Here’s a modification you could try:

function loadEdgeCommons(callback) {
    var script = document.createElement('script');
    script.src = 'path/to/edge_commons.js';
    script.onload = callback;
    document.head.appendChild(script);
}

loadEdgeCommons(function() {
    // Your existing code here
    setupAudio();
});

This approach should help ensure that EC is defined before you attempt to use it. Also, verify that you’re using the latest version of the Edge Commons library, as older versions might have compatibility issues with newer browsers.