Log in

View Full Version : 2 onMouseover functions: sound, & rollover



nycguurl
11-16-2007, 10:35 PM
Is there any way to have 2 onMouseover functions together? What I want is a rollover image, and the sound wav. I read in lots of places that this is possible if you put a semicolon in between, but it's not working. Can somebody help me? I had another thread going about the wav but this is a different topic now. There's nothing else on my page so you'll probably detect my fault right away. I'm a beginner, so can someone give me the exact thing to change where my script is wrong? Please? :o

Here's my example:
http://moneytreeaffiliates.com/Practice.htm

jscheuer1
11-16-2007, 10:49 PM
Your example page looks as though it may or may not suffer from other problems. However, there is no limit to the number of function executions that can be performed for a given event. They cannot, of course, directly conflict with each other, but that (other than proper syntax and general coding) is the only consideration. I see you have (from your source):


onMouseOver="EvalSound('sound1');javascript: this.src='images/Adobe_icon_2.bmp';"

The highlighted bit isn't needed (but shouldn't hurt in most cases). The 'word':

onMouseOver

should be all lower case letters for forward compatibility. Other than that, it is just a question of the two functions being valid on their own and compatible with each other.

nycguurl
11-17-2007, 02:17 AM
Hi John. :o
I changed the parts you said to. If it's still not working, does that mean the sound and the image rollover are just not compatible with each other? Whichever one I put first is the only one that will work.

jscheuer1
11-17-2007, 06:56 AM
Works fine here. There is a slight problem with the image rollover though. The path to the images is wrong:


this.src='images/Adobe_icon_2.bmp'

Opera doesn't seem to like the mouse down sound, but FF and IE are OK with it. The embed tag, which generally works well for sound in this case, is invalid, but I'm not going to worry about that right now. The sound playing function, though working, is poorly written, and can be reused (you only need one). Try this out:


<html>
<head>
<title>New Page 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">

function EvalSound(soundobj) {
document[soundobj].Play();
}

</script>
</head>
<body>
<embed src="Wav_1.wav" autostart=false width=0 height=0 name="sound1"
enablejavascript="true">
<embed src="Wav_2.wav" autostart=false width=0 height=0 name="sound2"
enablejavascript="true">
<p align="center"><a href="http://google.com"><img border="0"
src="Adobe_icon.gif"
onmouseover="EvalSound('sound1');this.src='Adobe_icon_2.bmp';"
onmouseout="this.src='Adobe_icon.gif';"
onmousedown="EvalSound('sound2');this.src='Adobe_icon.gif';"
width="32" height="32"></a></p>
</body>
</html>

nycguurl
11-17-2007, 05:40 PM
Ohmygosh I feel so stupid. I had the image in the wrong place. LoL :rolleyes:

Ok, I fixed everything you said and now voila! Thank you!!! :)

jscheuer1
11-17-2007, 05:53 PM
You didn't really do what I did, but you are getting closer. The main difference now is that your onmouseout image is the same as your onmouseover image. It should be the same as the original image. Also, although you removed the second sound function, you didn't upgrade the one that you kept.

I played around with this idea a bit more and discovered that the reason Opera doesn't like the onmousedown sound has something to do with the sound file itself, a different wav file might work onmousedown with Opera. I also made an improvement to the sound function to prevent an error message for browsers that don't support it. And, you really should use the type attribute with the script tag:


<script type="text/javascript">
function EvalSound(soundobj) {
if(typeof document[soundobj].Play != 'undefined')
document[soundobj].Play();
}
</script>

nycguurl
11-18-2007, 06:39 PM
Yikes, you are right, I didn't do exactly what you said. I must have missed that. I am properly chastised. LoL :rolleyes:
Also, the image mouseovers are in the right places now.

When you said:

Also, although you removed the second sound function, you didn't upgrade the one that you kept.


What do you mean? :confused:
Is it upgraded now with the code you gave me?

jscheuer1
11-18-2007, 08:09 PM
Is it upgraded now with the code you gave me?

Yep! A lot of this stuff has nothing to do with javascript exactly. At times it would help to have a look at what you are telling the browser to do, and see if it's what you want to be telling it. For example, the onmousedown image path is still (or again) incorrect. That's just a proofreading/typo sort of error though. Nothing to get too excited about.

nycguurl
11-18-2007, 08:59 PM
Umm.. I get excited about everything, LoL :o
I better go check it out...

Ok, I'm back, and it's fixed.
By the way, those yucky sounds are just for practice, not the real ones I'm using.
I'll be back if I need to as I incorporate this onto my real page now.