A big advantage of using external code libraries is that whenever you need to make a change to the code, no matter if it is an update or a correction, there is a single place to modify, which greatly eases the task and preserves your sanity. This doesn't mean that you dont need to test your code after modifications, it means that modifications are easier and dont involve editing lots of web pages.
Once the library is created you'll need to reference it from HTML so the functions and data that contains can be called from your HTML code. To reference an external code library use:
Remember that the text between quotes should contain the relative or absolute path to your library and the name of the .js file that contains your code.
Also bear in mind that it is recommended to insert references like the shown above between <HEAD></HEAD> tags to ensure your code is available as soon as possible.
To simplify things we will have the code to play and stop sounds inside the same function so we use a simple function call but, depending on the parameters sent to the function it will play or stop sounds.
|» Level Intermediate|
Rating: 6 Votes: 29
|My name is Gonzalo Alustiza and I work as a chief developer at Soundtown Argentina. Soundtown is a ten year old music production company specializing in music for advertising and TV which started to develop sonification solutions for the Internet.|
|Download the files used in this tutorial.|
|Download (89 kb)|
|More help? Search our boards for quick answers!|