rarebit Posted May 10, 2008 Share Posted May 10, 2008 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!) Quote Link to comment Share on other sites More sharing options...
bibby Posted May 11, 2008 Share Posted May 11, 2008 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. Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 11, 2008 Author Share Posted May 11, 2008 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? Quote Link to comment Share on other sites More sharing options...
haku Posted May 12, 2008 Share Posted May 12, 2008 var imgs = new Array(tot) equals var imgs = new Array(3); 'new Array(3)' won't work. Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 12, 2008 Author Share Posted May 12, 2008 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.