...

View Full Version : How can I get a sound to play on mouseover?



Poink
04-22-2004, 02:48 PM
Hello I am a total beginner when it comes to Java Scripting. I would like to know how to get a particular sound to play when I mouse over the link in this email protector script.

The source file would be "sounds/up_beep.au"


<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
user = "username";
site = "yoursite.com";

document.write('<a href=\"mailto:' + user + '@' + site + '\">');
document.write(user + '@' + site + '</a>');
// End -->
</SCRIPT>
</BODY>

Any help would be greatly appreciated. :confused:

sad69
04-22-2004, 06:43 PM
http://www.javascripter.net/faq/sound/onhover.htm

Sadiq.

Poink
04-22-2004, 10:20 PM
Thanks for replying Sad69 :thumbsup: I visited the site you mentioned and tried what was there. Unfortunately it didn't work for me :( This is my whole code old and new to make what I want a little more clearer.

Old code with two onMouseOver's one in <a href=""> tag and the other in <img=""> tag. The sounds play fine in this code:


<HEAD>
<SCRIPT LANGUAGE="javaScript">
<!-- Begin
function makesound(soundobj){
var thissound= eval("document."+soundobj)
thissound.play()
}
// End -->
</SCRIPT>
</HEAD>

<BODY>
<EMBED SRC="sounds/up_beep.au" AUTOSTART="false" HIDDEN="TRUE"
NAME="sound1" MASTERSOUND="MASTERSOUND">
<EMBED SRC="sounds/evac.au" AUTOSTART="false" HIDDEN="TRUE"
NAME="sound3" MASTERSOUND="MASTERSOUND">

<P>
<A HREF="mailto:joebloggs@mywebsite.com?subject=mysubjectmatterhere"
ONMOUSEOVER="makesound('sound1')" ONCLICK="makesound('sound3')">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
mailbutton=new Image()
mailbutton.src="images/down_mail.gif"
// End -->
</SCRIPT>

<IMG SRC="images/mail.gif" ONMOUSEOVER='this.src="images/down_mail.gif"'
ONMOUSEOUT='this.src="images/mail.gif"' STYLE="cursor:hand" WIDTH="128"
HEIGHT="34" BORDER="0">
</A>
</P>
</BODY>

This is my new code with the email protector script, I am so fed up with spam mail it's unbelievable. As you can see my <a href=""> tags are now in the JavaScript and I only have one onMouseOver in the <img=""> tag:


<HEAD>
<SCRIPT LANGUAGE="javaScript">
<!-- Begin
function makesound(soundobj){
var thissound= eval("document."+soundobj)
thissound.play()
}
// End -->
</SCRIPT>
</HEAD>

<BODY>
<EMBED SRC="sounds/up_beep.au" AUTOSTART="false" HIDDEN="TRUE"
NAME="sound1" MASTERSOUND="MASTERSOUND">
<EMBED SRC="sounds/evac.au" AUTOSTART="false" HIDDEN="TRUE"
NAME="sound3" MASTERSOUND="MASTERSOUND">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
user = "joebloggs";
site = "mywebsite.com?subject=my_subject_matter_here";
document.write('<a href=\"mailto:' + user + '@' + site + '\">');

mailbutton=new Image()
mailbutton.src="images/down_mail.gif"
// End -->
</SCRIPT>

<IMG SRC="images/mail.gif" ONMOUSEOVER='this.src="images/down_mail.gif"'
ONCLICK="makesound('sound3')" ONMOUSEOUT='this.src="images/mail.gif"'
STYLE="cursor:hand" WIDTH="128" HEIGHT="34" BORDER="0">
</A>
</BODY>

Is their a simple way to put my source name="sound1" from the first <embed src=""> tag in the onMouseOver in my new script, like I have done with the OnClick="makesound('sound3')?

Any help is really appreciated, thank you. :D

sad69
04-22-2004, 10:58 PM
I think you need to take a second look at that link I posted. Notice how it refers to the play and stop methods? There's a link at the bottom of the page that shows you what the play and stop methods look like.

Follow that example exactly. You don't need that embedded stuff you're doing.. I don't think so at least.

Good luck,
Sadiq.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum