View Full Version : Image rollover and sound

03-23-2005, 05:25 AM
I've been experimenting with Javascript in making a protoype webpage. Note: my knowledge of Javascript is very limited, I found tutorials on the net that explained what I needed to do and modified the code for my own use.

Basically, for the page I am working on currently, there need to be three Javascript functions. I've worked out the first two, the third is actually a combination of these two.

The first function swaps an image for onMouseover.
The second function plays a sound whenever a picture on the page is clicked.

I've tried to combine the functions with little success so far.
What I need to happen is have the images "swap" while the sound plays (this happens when the image is clicked with the mouse), which should both be triggered by onClick. The image also has to be constrained by the height command, although this isn't strictly necessary if the function works.

And I need to have all three functions run on the same page. The third function needs to be created anew.

I would greatly appreciate any help I can get.

Here is the code, extracted from the webpage:

<script language="JavaScript" type="text/javascript">
image1of = new Image(); image1of.src = "Return_Off.gif";
image1on = new Image(); image1on.src = "Return_On.gif";

function imageReplace() {
var args = imageReplace.arguments;
for (var i = 0; i < args.length; i = i + 2) {
document[args[i]].src = eval(args[i + 1] + ".src");
// -->

function EvalSound(soundobj) {
var thissound= eval("document."+soundobj);

<embed src="Cmctr.wav" autostart=false hidden=true name="sound1"

<img src="M\Mnnctr.gif" width="150" onClick="EvalSound('sound1')">

<a href="javascript:history.go(-1)"
onMouseout= "imageReplace('image1','image1of');"
<img src="Return_Off.gif" name="image1"
alt="Return" border="0"></a>

03-23-2005, 10:28 AM
--> Shifting to JavaScript.