On the way home from work today, I was thinking about one deficiency that DHTML seems to have that Flash doesn’t. That is the ability to play sound. Now, I’m not a fan of sounds on web pages, and usually not even web apps, but there are some instances where could be useful if used appropriately. I’m thinking of things like an online chat app that make a little ping noise when someone sends an message and your focus is elsewhere. Those kinds of things are really helpful and should be easier to include.
I’ve started working on such a tool. It’s basically a little flash applet that you embed in your page. It’s designed to not be visible and actually not do anything but play sounds. Now here’s the cool thing about it. Once it’s loaded, it actually creates some javascript functions on the page so you don’t have to even think about it being a flash application and not native functionality.
Here it is: Sound Board v0.2
Usage
The api couldn’t be simpler. There are two methods, loadSound(name, url) and playSound(name). You need to load a sound clip before you can use it. You have the option of either giving the sound a nickname for referring to it later or not. If you choose not to, you pass the url only to both the load and play functions.
loadSound('mySound', '/sounds/mySound.mp3');
playSound('mySound');
or
loadSound('/sounds/mySound.mp3');
playSound('/sounds/mySound.mp3');
That’s about all there is to it. In the zip file there is a bit of js that you can include to make sure things fail gracefully if flash is not available. There’s also the full ActionScript source of the flash component.
Note
This should be easy enough to use at this point, but it’s still pretty unpolished. You’re welcome to do with it as you wish, just try to use it wisely. Sound on websites is generally a bad idea.