SoundManager2 and require.js

Flash SoundManager2 requires the global JavaScript variable (soundManager), which will be present in the global scope. Thus, the flash player interacts with the SoundManager2 JavaScript API.

The problem is that when you want to build your web application using AMD (require.js), you have to compromise and allow this global variable to be present.

Is there a way to not disrupt the way I create an AMD application, including SoundManager?

+4
source share
1 answer

Use RequireJS shim config to wrap your non-AMD library as a module that exports a global variable: http://requirejs.org/docs/api.html#config-shim

requirejs.config({ paths: { 'soundmanager2' : 'some/path/soundmanager2' }, shim: { 'soundmanager2': { exports: 'soundManager' } } }); 

Then you need to perform SoundManager2 laying, like any other dependency, and use it in your own modular code:

 define(['soundmanager2'], function(soundManager) { soundManager.setup({ ... }); soundManager.beginDelayedInit(); // The following may help Flash see the global. window.soundManager = soundManager; return soundManager; }); 
+6
source

Source: https://habr.com/ru/post/1433977/


All Articles