Jump to content

Baffaling Slide Show


rarebit

Recommended Posts

I have the following page:

<html>
<head>
<script type="text/javascript">
img_num = 0;
inames = new Array("monkey_01.gif", "monkey_02.gif", "monkey_03.gif");
imgs =new Array();
tot = imgs.length;
for(i=0;i<tot;i++)
{
imgs[i] = new Image();
imgs[i].src = inames[i];
}

function animated()
{
document.aimg.src = imgs[img_num].src;
img_num++;
if(img_num>tot)
{
	img_num = 0;
}
n = setTimeout('animated();', 3000);
}
</script>
</head>
<body>
<br><br>
<img name='aimg' src='monkey_03.gif' onload='animated()'>
<br>
</body>
</html>

 

However I get the following error:

Error: imgs[img_num] has no properties

 

I've tried dumping the vars and eerything seems ok, except it then say's 'animated()' doesn't exist.

 

I'm baffaled! (p.s. I'm also baffaled at how to spell baffaled!)

Link to comment
Share on other sites

with comments

 

img_num = 0;
inames = new Array("monkey_01.gif", "monkey_02.gif", "monkey_03.gif");
imgs =new Array();
tot = imgs.length;   //  tot is 0 , you just made imgs above.
for(i=0;i<tot;i++)   //  never runs. tot is 0.  I think you want inames.length
{
imgs[i] = new Image();
imgs[i].src = inames[i];
}

 

..should be fine after that.

Link to comment
Share on other sites

i've already changed it to:

var inames = new Array("monkey_01.gif", "monkey_02.gif", "monkey_03.gif");
var tot = inames.length;
var imgs = new Array(tot);

and still same probs...

However it seems to crash firefox, so i'm wondering if it's a prob there?

Link to comment
Share on other sites

Why? (I can see a possible issue, but)

Thats how my book does it and same here

 

Right, this is how the script looks now:

<script type="text/javascript">
var n;
var img_num = 0;
var inames = new Array("monkey_01.gif", "monkey_02.gif", "monkey_03.gif");
var tot = inames.length;
var imgs = new Array();
for(i=0;i<tot;i++)
{
imgs[i] = new Image();
imgs[i].src = inames[i];
}

function animated()
{
document.aimg.src = imgs[img_num].src;

img_num++;
if(img_num>=tot)
{
	img_num = 0;
}
n = setTimeout('animated()', 30000);
}
</script>

 

When it runs, it flips through the images 10 times a second at least, then hangs Firefox and I have to force quit?

 

p.s. thanks for help, but I think it should be working either way!

Link to comment
Share on other sites

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.