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
https://forums.phpfreaks.com/topic/105019-baffaling-slide-show/
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
https://forums.phpfreaks.com/topic/105019-baffaling-slide-show/#findComment-538062
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
https://forums.phpfreaks.com/topic/105019-baffaling-slide-show/#findComment-539134
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.