I've been looking for quite some time to do something that I'm sure is simple, but I can't find the answer. I have found a few general tutorials on this, but have not been able to get it to work with anything I've tried so far. I'm sorry if I missed it, but I appreciate any help anyone can provide.
I have a simple button that I built in flash a while ago that I am converting to an HTML canvas document so I can place it as HTML content in a website with animation and sound on mouseover. I've got the animation working the way I want it when I publish to HTML, but using ActionScript 3, I had a sound that played when the user moused over the button. I want to have it still play a sound when the user mouses over it in my html content too, but I have not had success yet with converting my ActionScript to JavaScript and I don't really know JavaScript.
I would also like to have multiple fallback formats (ogg, wav) of the audio file linked in the code for any browsers that don't work with mp3 files. I can convert the audio file no problem but don't know how to code this in JavaScript….
Here is the ActionScript code which works fine in my original document when I export as a .swf file.
stop();
import flash.media.Sound;
import flash.net.URLRequest;
import flash.events.Event;
sprayGunbtn.addEventListener(MouseEvent.MOUSE_OVER, playSound);
var myExternalSound:Sound = new Sound();
var req:URLRequest = new URLRequest("ShortSpray.mp3");
myExternalSound.load(req);
function playSound(event:Event){
myExternalSound.play();
}
If someone could help me convert this ActionScript 3 code to JavaScript so that it will work when I publish my .fla file to HTML, I would greatly appreciate it. Thanks in advance!