Jump to content

Recommended Posts

 

 

I am building a site to help my students practice their multiplication skills. I needed to be able to click on the number and get a new random number. I got that working just fine with the following script:

<SCRIPT LANGUAGE="JavaScript"><!-- Begin
var rand1 = 0;
var useRand = 0;

images = new Array;
images[1] = new Image();
images[1].src = "image1.gif";
images[2] = new Image();
images[2].src = "image2.gif";
images[3] = new Image();
images[3].src = "image3.gif";
images[4] = new Image();
images[4].src = "image4.gif";
images[5] = new Image();
images[5].src = "image5.gif";
images[6] = new Image();
images[6].src = "image6.gif";
images[7] = new Image();
images[7].src = "image7.gif";
images[8] = new Image();
images[8].src = "image8.gif";
images[9] = new Image();
images[9].src = "image9.gif";
images[10] = new Image();
images[10].src = "image10.gif";
images[11] = new Image();
images[11].src = "image11.gif";
images[12] = new Image();
images[12].src = "image12.gif";
images[13] = new Image();
images[13].src = "image13.gif";
images[14] = new Image();
images[14].src = "image14.gif";
images[15] = new Image();
images[15].src = "image15.swf";  *******I want this to play.*******


function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}
//  End -->
</script>

 

I then had the bright idea to play a sound when one of the images comes up. I figured Flash was the easiest way so I made it. Alone the .swf plays fine but if I enter it into the script all I get is a broken image icon.  You can see the site here: http://www.westis4me.com/whammy/2.html

 

Can anyone suggest a workaround or different method?

Thanks Will

An SWF file is not an Image.

 

images[15] = new Image();
images[15].src = "image15.swf";

 

That's the object equivalent of:

 

<img src="image15.swf">

 

There's a very popular JavaScript plug-in you can use called SWFObject, that makes embedding flash objects far easier. Using that you don't need to worry about browser compatibility issues or standards compliance, and it provides a simple API for working with in JS. That said, I rarely ever use Flash so I'm not at all experienced with it. I've just read it's good...

You're best off using Flash to be honest. Browsers lack[ed] any kind of standard for how to handle playing audio files, and it basically ended up in a big mess. That is up until HTML5 of course, but you can't depend on your user having an up-to-date browser. Most JavaScript solutions use a Flash player in the background though..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.