By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,184 Members | 1,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,184 IT Pros & Developers. It's quick & easy.

How do I get code to access the images at the URL given?Array Question

tpgames
100+
P: 785
How do I get code to access the images at the URL given?
I'd like the user to be able to select which theme of images they want to view then the script would randomly pick an image to show.

Expand|Select|Wrap|Line Numbers
  1. <!--BEGIN
  2. // Customising Variables
  3.  
  4. // Arrays of Images that can be used in the game
  5. var ImgAry=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  6. var ImgAry2=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  7. var ImgAry3=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  8. var ImgAry4=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  9. var ImgAry5=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  10. var ImgAry6=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  11. var ImgAry7=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg'];
  12.  
  13.  
  14.  
  15. // The SelAry is used to populate the Select Images SelectList
  16. var SelAry=[];
  17. // Each field is an array defining an option
  18. // field 0 = the text to be displayed in the option
  19. // field 1 = the directory path for the images
  20. // field 2 = the image file names]
  21. SelAry[0]=[];
  22. SelAry[1]=['The Pilot Episode','http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/pilot1/',ImgAry];
  23. SelAry[2]=['The Origin Story','http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/tos1/',ImgAry2];
  24. SelAry[3]=['The Culex Experiment','http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/tce1/',ImgAry3];
  25. SelAry[4]=['Monsoon Man','http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/mm1/',ImgAry4];
  26. SelAry[5]=['The Rameses Connection','http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/trc1/',ImgAry5];
  27. SelAry[6]=['The Living Stones','http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/tlstones1/',ImgAry6];
  28. SelAry[7]=['Audio Series','http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/audio1/',ImgAry7];
  29.  
  30.  
  31. var j = 0
  32. var q = ImgAry.length;
  33.  
  34. var preBuffer = new Array()
  35. for (i = 0; i < q; i++){
  36.    preBuffer[i] = new Image()
  37.    preBuffer[i].src = ImgAry[i]
  38. }
  39.  
  40. var whichImage = Math.round(Math.random()*(q-1));
  41. function showImage(){
  42. document.write('<img src="'+ImgAry[whichImage]+'" width=\"640\" height=\"456\">');
  43. }
  44.  
  45.  
  46. //  End -->
  47. </script>
Mar 28 '07 #1
Share this Question
Share on Google+
18 Replies


iam_clint
Expert 100+
P: 1,208
I guess i really don't understand your question you showed code whats wrong with the code?
Mar 28 '07 #2

iam_clint
Expert 100+
P: 1,208
Expand|Select|Wrap|Line Numbers
  1. function showImage(whichstyle){
  2. var style = SelAry[whichstyle];
  3. style = style[1];
  4. document.write('<img src="'+style+ImgAry[whichImage]+'" width=\"640\" height=\"456\">');
  5. }
  6.  
  7. //  End -->
  8. </script>
  9. <input type="button" onclick="showImage(1);" value="click me!">
  10.  
you mean something like this?
Mar 28 '07 #3

tpgames
100+
P: 785
I can't get any images to show up. I'm trying to get the code to recognize the array and recognize the image URL. I'm attempting to make it so the JS is on its own page and is called to the html page.

The user would have a menu to select a theme from. I've not put that code in yet, forgot. Babysitting and new to JS = Confusion. LOL Thanks!

The Link to page

This is what I did on another page:
Page 1

The images show up, but don't use an image array I like. I'd rather just use images array whereby I only have to change the link and title to get what I want, which is why I copied code from a memory game.
Mar 28 '07 #4

tpgames
100+
P: 785
Better idea: Forget selecting the theme from within the page. Instead, use simple html link to theme instead of selection box that doesn't work.

Use page 1 script. But, alter it to handle Arrays in this format:
Expand|Select|Wrap|Line Numbers
  1. var ImgAry=new Array();
  2. // Each field is an array defining an option
  3. // field 0 = the directory path for the images
  4. // field 1 = the image file names
  5. // field 2 = width and height]
  6. ImgAry[0]=['http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/tlstones1/',ImgAry1, 640,556];
  7. ImgAry[1]=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  8.  
How do I do this? I'd like it to randomly choose an image in the folder. The above code does NOT work!
Currently, I get the error
http://www.tpgames.net/gaming/2/word/cipher/f/undefined

Current Page 1
Thanks!
Mar 29 '07 #5

tpgames
100+
P: 785
NEW CODE:

Expand|Select|Wrap|Line Numbers
  1. var theTPImg = new Array();
  2. ImgUrl[0]=['http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/tlstones1/'];
  3. theTPImg[1]=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  4.  
  5. var newBanner = 0;
  6. var totalBan = theTPImg.length;
  7.  
  8. function cycleBan() {
  9.   newBanner++;
  10.   if (newBanner == totalBan) {
  11.     newBanner = 0;
  12.   }
  13.   document.banner.src= "'+ImgUrl+' 'theTPImg[newBanner]'";
  14.   // set the time below for length of image display
  15.   // i.e., "4*1000" is 4 seconds
  16.   setTimeout("cycleBan()", 4*1000);
  17. }
  18. window.onload=cycleBan;
  19.  
  20.  

Found here

The issue: It says the url is wrong. Actually, I probably have
this code wrong:
Expand|Select|Wrap|Line Numbers
  1.   document.banner.src= "'+ImgUrl+' 'theTPImg[newBanner]'";
Its not recognizing the url variable. How should this code be written? Thanks!

This code would have the array I want.
Mar 29 '07 #6

tpgames
100+
P: 785
CORRECTION:
The issue: Not changing the images at all. Only displays 1.jpg
This code is probably wrong, but don't know how to fix it.
Expand|Select|Wrap|Line Numbers
  1.   document.banner.src= "'+ImgUrl+' 'theTPImg[newBanner]'";
Its not recognizing the url variable. How should this code be written? Thanks!

This code would have the array I want.
(try editing, got the edit box but then it timed out and gave me the can not edit page! Foolish program. Should not time out within 30 seconds of saying I'm within the time limit!)
Mar 29 '07 #7

P: 54
ok.. lets forget about what you already have!
i tried to look at your code and im even more confused now :P

can you try to explain exactly what you want to do?
Mar 29 '07 #8

tpgames
100+
P: 785
Clarification:
I'm trying to avoid having to add the URL of the image to every single image in the array and avoid making the image array
[html]
http://www.url.com/name1.jpg., http://www.url.com/name2.jpg, ect. for all 135 images.
[/html]
(Just in case it tried treating it as html anyhow, I added tags.)
Mar 29 '07 #9

tpgames
100+
P: 785
This uses the original variable names with bannerImg.
The // indicates the original scripts array, with the images in the same folder as the script. My images are hosted at photob...dotCom, instead of at my site. I'm attempting to use an array to define the URL where the images are located, and a Array of the image names. I'm also attempting to have the code recognize the url of the images and attach it to the image names and display this image. Currently, the images will rotate like in a banner.

Expand|Select|Wrap|Line Numbers
  1. var bannerImg = new Array();
  2.   // Enter the names of the images below
  3.  // bannerImg[0]="image_jss.gif";
  4.  // bannerImg[1]="image_js.gif";
  5.  // bannerImg[2]="image_wr.gif";
  6.  
  7.  
  8. ImgUrl[0]=['http://i107.photobucket.com/albums/m287/tpkyteroo/zgames/memory/tlstones1/'];
  9. bannerImg[1]=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  10.  
  11. //The rest of the original code is below.
  12.  
  13. var newBanner = 0;
  14. var totalBan = bannerImg.length;
  15.  
  16. function cycleBan() {
  17.   newBanner++;
  18.   if (newBanner == totalBan) {
  19.     newBanner = 0;
  20.   }
  21.   document.banner.src=bannerImg[newBanner];
  22.   // set the time below for length of image display
  23.   // i.e., "4*1000" is 4 seconds
  24.   setTimeout("cycleBan()", 4*1000);
  25. }
  26. window.onload=cycleBan;
What I tried to do in my code was get ImgUrl and bannerImg to work together to display an image. My code was wrong, and don't know how it should be written. Here, I left my code out as it was all wrong.
Thanks!
Mar 29 '07 #10

P: 54
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  
  3. <html>
  4. <head>
  5. <title>Random images same url</title>
  6. </head>
  7.  
  8. <style>
  9.  
  10. #bgHolder {height:12px; width:12px; display:block; overflow:hidden;}
  11.  
  12. </style>
  13.  
  14. <body>
  15.  
  16. <div id="bgHolder">
  17.  
  18. </div>
  19.  
  20. </body>
  21.  
  22. <script>
  23.  
  24. imgName = new Array()
  25. imgName[0] = "yellow"
  26. imgName[1] = "blue"
  27. imgName[2] = "orange"
  28. imgName[3] = "purple"
  29. imgName[4] = "brown"
  30.  
  31. contextPath = "bgs/";
  32. extension = ".gif";
  33. current = 0;
  34.  
  35. window.onload = randomizeImage
  36.  
  37. function randomizeImage() {
  38.  
  39. changeImg()
  40. }
  41.  
  42. function changeImg() {
  43. holder = document.getElementById("bgHolder");
  44. holder.style.background="url(" + contextPath + imgName[current] + extension + ")";
  45.  
  46. if (current < imgName.length-1) {    current = current+1 }
  47.  
  48. else { current = 0 }
  49.  
  50. setTimeout('randomizeImage()',2000);
  51. }
  52.  
  53. </script>
  54.  
  55. </html>
  56.  
  57.  
Something like this?
I dont got why you were using one array to store a single path... you can use just a variable for that instead of the array[0]
Mar 30 '07 #11

tpgames
100+
P: 785
I was trying to save typing by using some code I had from another game. If I can use the image array in the format I had it, then I don't have to type in 135 [# here]'s.

I'll try your code and see how it works, then submit a new reply.
Mar 30 '07 #12

tpgames
100+
P: 785
I can't get it to work using this:
Expand|Select|Wrap|Line Numbers
  1. imgName[0] = ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg','8.jpg','9.jpg','10.jpg','11.jpg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg','19.jpg','20.jpg','21.jpg','22.jpg','23.jpg','24.jpg','25.jpg','26.jpg','27.jpg','28.jpg','29.jpg','30.jpg','32.jpg','33.jpg','34.jpg','35.jpg','36.jpg','37.jpg','38.jpg','39.jpg','40.jpg','41.jpg','42.jpg','43.jpg','44.jpg','45.jpg','46.jpg','47.jpg','48.jpg','49.jpg','50.jpg','51.jpg','52.jpg','53.jpg','54.jpg','55.jpg','56.jpg','57.jpg','58.jpg','59.jpg','60.jpg','61.jpg','62.jpg','63.jpg','64.jpg','65.jpg','66.jpg','67.jpg','68.jpg','69.jpg','70.jpg','71.jpg','72.jpg','73.jpg','74.jpg','75.jpg','76.jpg','77.jpg','78.jpg','79.jpg','80.jpg','81.jpg','82.jpg','83.jpg','84.jpg','85.jpg','86.jpg','87.jpg','88.jpg','89.jpg','90.jpg','91.jpg','92.jpg','93.jpg','94.jpg','95.jpg','96.jpg','97.jpg','98.jpg','99.jpg','100.jpg','101.jpg','102.jpg','103.jpg','104.jpg','105.jpg','106.jpg','107.jpg','108.jpg','109.jpg','110.jpg','111.jpg','112.jpg','113.jpg','114.jpg','115.jpg','116.jpg','117.jpg','118.jpg','119.jpg','120.jpg','121.jpg','122.jpg','123.jpg','124.jpg','125.jpg','126.jpg','127.jpg','128.jpg','129.jpg','130.jpg','131.jpg','132.jpg','133.jpg','134.jpg','135.jpg'];
  2.  
It will only work if I use exactly your set up which means a lot of coding. However, I'd only have to do it once. I'd have to get rid of the .jpg, and type in
Expand|Select|Wrap|Line Numbers
  1. imgName[0] = ['1']; imgName[1] = ['2']; ect. 135 times! 
I just thought there was a short cut somewheres. Some simple line of code that I had wrong or something. Thanks!
Mar 30 '07 #13

tpgames
100+
P: 785
I typed in that bottom code wrong! Sorry! But the point is, I'd have to type in what you did 135 times.
Mar 30 '07 #14

tpgames
100+
P: 785
It doesn't show the entire image either. It only shows a tiny corner.

5.html
Mar 30 '07 #15

P: 54
It doesn't show the entire image either. It only shows a tiny corner.

5.html
sure it will not work man... look at the code

Expand|Select|Wrap|Line Numbers
  1. <style>
  2.  
  3. #bgHolder {height:12px; width:12px; display:block; overflow:hidden;}
  4.  
  5. </style>
  6.  
  7. <body>
  8.  
  9. <div id="bgHolder" width="200" height="200">
  10.  
you are trying to change the size of the div by putting attributes on the tag while the css ive made was to show images of 12px with overflow! (because i did the example using small arrow images)
so... change the CSS not the tag div!

and second
whats wrong with the old loop?

Expand|Select|Wrap|Line Numbers
  1. imgName = new Array()
  2. for (x=0; x<=4; x++) {
  3. imgName[x] = x
  4. }
  5.  
just do that and you dont have to write one zillion times!
Mar 30 '07 #16

P: 54
completing the last post...
the ideia of using one array at first time was because i thought you had images with different names and etc...

if you are going to use numbers instead of names, you dont even gonna need the array!!

if you already do the loop to set the value of the array[x] you can instead get that x from the loop and change the images without the array
Mar 30 '07 #17

tpgames
100+
P: 785
Thanks! That should work. I've not learned the ins and outs of "div" tags. When I've tried using them in the past, I got a nightmare of a page. LOL So stuck to simple tables, tr, td ect. tags. I'm also still learning how to use CSS for tables and all. Just learning this.
Mar 31 '07 #18

tpgames
100+
P: 785
Just tested it. Everything works well. Thanks a lot! I greatly appreciate it. :>)
Mar 31 '07 #19

Post your reply

Sign in to post your reply or Sign up for a free account.