Output:
Description:
Load sound.
Result:
Output 'Loaded ../../examples/resource/in.wav!' and 'Loaded ../../examples/resource/out.wav!'.
Code:
var sources = null; function onload() { var urls = ['../../examples/resource/in.wav', '../../examples/resource/out.wav']; var engine = new jWebAudio.SoundEngine(); sources = engine.addSoundSource({ 'url': urls }); for (var i in sources) { sources[i].load(function(url) { return function() { var para = document.createElement('p'); var output = document.createTextNode('Loaded ' + url + '!'); para.appendChild(output); document.getElementById('output').appendChild(para); }; }(urls[i])); /* Notice that the following is the wrong way to pass callback * functions to load. Every anonymous callback function has the * onload activation object in its scope chain, referring to * the same i. When onload returns, the value of i is 1 in this * case, so it will output 'Loaded ../../examples/resource/out.wav!' * twice. * * See JavaScript closure and scope chain for more information. * * sources[i].load(function() { * var para = document.createElement('p'); * var output = document.createTextNode('Loaded ' + urls[i] + '!'); * para.appendChild(output); * document.getElementById('output').appendChild(para); * }); */ } }