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

Confused on how to get link to image correct in this code.

P: 785
I have my images at a different site, and wanted the game to access those images. I've changed the links in the other parts of the code, but still get a undefined error, and thought that the below code has the image links wrong, because I didn't add a URL to the code. I'm not sure how to add the URL. Thanks

Here's the specific src codes:
Expand|Select|Wrap|Line Numbers
  1. <img src="'+cardbg.src+'" width=120 height=140 alt="" name="k'+i+'" border=0>
  3. <img src="'+ima_a[i].src+'" width=120 height=140 alt="" name="s'+i+'" border=0>
  5. <img src="'+ima_a[i].src+'" width=120 height=140 alt="" name="s'+(i+4)+'" border=0>
Here is the code in its context:
Expand|Select|Wrap|Line Numbers
  1. <img src="'+cardbg.src+'" width=120 height=140 alt="" name="k'+i+'" border=0></a></div>';
  2.   }  
  3.   document.writeln(temp);   
  4. }
  6. function block2()
  7. { var temp='';
  8.   for (var i=0; i<4; i++) 
  9.   { temp=temp+'<div id="s_'+i+'" style="position:absolute; top:'+(yoff+i*dy)+'px; left:'+xoff_s+'px; width:'+dx+'px; height:'+dy+'px; zIndex:0">';
  10.     temp=temp+'<a href="javascript:ablage('+i+')"><img src="'+ima_a[i].src+'" width=120 height=140 alt="" name="s'+i+'" border=0></a></div>';
  11.     temp=temp+'<div id="s_'+(i+4)+'" style="position:absolute; top:'+(yoff+i*dy)+'px; left:'+(xoff_s+dx)+'px; width:'+dx+'px; height:'+dy+'px; zIndex:0">';
  12.     temp=temp+'<a href="javascript:ablage('+(i+4)+')"><img src="'+ima_a[i].src+'" width=120 height=140 alt="" name="s'+(i+4)+'" border=0></a></div>';
And here is the beginning part of the code, where the URL has been defined:
Expand|Select|Wrap|Line Numbers
  1. var leer=new Image;   leer.src='leer.gif';     
  2. var cardbg=new Image; cardbg.src='cardbg.gif'; 
  3. var ima_c =new Array();
  4. var ima_ca=new Array();
  5. var ima_a =new Array();
  6. for (i=0; i<52; i++)
  7. { ima_c[i] =new Image(); ima_c[i].src='c'+i+'.gif'; 
  8.   ima_ca[i]=new Image(); ima_ca[i].src='c'+i+'a'+'.gif'; 
  9. }
  10. for (i=0; i<4; i++) { ima_a[i]=new Image(); ima_a[i].src='a'+i+'.gif'; }
Its a 9 Patience type game. Thanks!
Jun 11 '07 #1
Share this Question
Share on Google+
5 Replies

P: 785
Wrong Beginning Code!
Here is the CORRECT code with the URL's defined:
Expand|Select|Wrap|Line Numbers
  1. <!-- Code copyrighted by Ujas at -->
  3. <script language="Javascript" src=""></script>
  4. <script language="javascript">
  6. zmax=104,rmax=9,kmax=4,smax=8,dx=120,dy=140,dy2=12,xoff=12,yoff=64,xoff_s=xoff+rmax*dx+8, xoff_t=xoff_s+2*dx+8;
  7. var count,index,i,gewaehlt,x_alt;
  8. var karte=new Array(zmax); 
  9. var stack=new Array(8);    
  10. var karten_pro_spalte=new Array(rmax);
  11. var f=new Array(rmax*zmax);
  12. var liste=new Array(zmax);
  13. var xyz=new Array(3);
  15. // ----- Bilder vorladen: --------------------------------------------------------------
  17. var leer=new Image;   leer.src='';     
  18. var cardbg=new Image; cardbg.src=''; 
  19. var ima_c =new Array();
  20. var ima_ca=new Array();
  21. var ima_a =new Array();
  22. for (i=0; i<52; i++)
  23. { ima_c[i] =new Image(); ima_c[i].src=''+i+'.jpg'; 
  24.   ima_ca[i]=new Image(); ima_ca[i].src=''+i+'a'+'.jpg'; 
  25. }
  26. for (i=0; i<4; i++) { ima_a[i]=new Image(); ima_a[i].src=''+i+'.jpg'; }
Jun 11 '07 #2

Expert Mod 15k+
P: 16,027
Which line do you get an error on?
Jun 12 '07 #3

P: 785
According to the JavaScript console, there is no error.
I just get a card undefined when I push 'deal to rows' button or 'new draw'.

The only thing I thought I was doing differently from the original script was having the images hosted at a different site, rather than have them in the same folder as the file. I wasn't aware that I had inadvertently changed anything else in the code.

Here's the link to the game:
9 solitaire

I'm going to upload the images to the same folder and upload the original script and see what gives. I'll post a result in a few. Thanks!
Jun 12 '07 #4

P: 785
Okay, I didn't realize that my javascript console was changed to not auto give errors. After I clicked on show errors, I receive this from my version of the game:
too much recursion line 146 of b.js
my_obj has no properties line 134 of b.js

I also realized, that I had moved the html links to a different location. The only other change I had made was making the cards larger.

However, the cards never deal, New Game doesn't show me cards dealt on my version of game. And, I'm wondering when JS will start making sense to me. LOL

Here is the link to the Original script:
Original Script

Original b.js

I am now more confused then before. What I thought was wrong, I'm not seeing as not wrong. Thanks!
Jun 12 '07 #5

P: 785
I figured out that when I don't have 2 div tags in, the game doesn't work.

So, I've solved the issue. Thanks!
Jun 12 '07 #6

Post your reply

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