PDA

View Full Version : Help with Adding sound to a button when clicking.


Zrikz
11-12-2002, 10:59 PM
Ive tryed the script many times doing different things. Im trying to make my icon that I made have a sound when either having mouse over it or clicked either would work. The page is wwww.starwarsgalaxies.homestead.com/index.html it has the sound file there and the icon I just cant figure it out been working at it for a hour or 2.

Thanks for the help
Mike

Zrikz
11-12-2002, 11:12 PM
I am using this script. Unsure what to do with the laser.wav Ive tryed the name of mine.wav the link and no avail

Also unsure which of these to use.

- onMouseOver/onMouseOut sound:
<A HREF="YourPage.html" onMouseOver="playSound(0)" onMouseOut="stopSound(0)">Move mouse over to play sound</A>

- onClick sound:
<A HREF="javascript:playSound(0);">Click here to play sound</A>

-With a button:
-
<INPUT TYPE="BUTTON" VALUE="Click me!" onClick="playSound(0)">


<script LANGUAGE="JavaScript"><!--
// Preload and play audio files with event handler (MouseOver sound)
// designed by JavaScript Archive, (c)1999
// Get more free javascripts at http://jsarchive.8m.com

var aySound = new Array();
// Below: source for sound files to be preloaded
aySound[0] = "Laser.wav ";

// DO NOT edit below this line
document.write('<BGSOUND ID="auIEContainer">')
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
//-->
</script>

Zrikz
11-13-2002, 01:23 AM
Any thoughts anyone? its obviously done as the examples work just need some details please.

Mike

^KoalaBear^
11-15-2002, 07:41 PM
Not sure if this is what you're after... but try it and possibly amend it for a button or image.jpg anyway.

<center><a href="#" onClick="document.all.music.src='sound.wav'">Click
here for sound</a>
<p><a href="#" onMouseOver="document.all.music.src='sound.wav'">Move the
mouse over here for sound</a></center>
<bgsound src="#" id=music loop=1 autostart="true">
<br>&nbsp;
</center>

Cheers
KB...
:thumbsup: