Solved

Loading Images from xml file

Posted on 2013-06-17
4
340 Views
Last Modified: 2013-06-18
I have a baseball field and I need to load each team players uniform. I wrote code for it and checked it in Fire Bug but Fire bug didn't display any messages.

here is the part that loads player uniforms on the field Attached is a Zip file that contains all necessary files and is hardcoded to work without any tweaking

var d = $(data);
 				var Team = $(d.find('TeamID'));
				var d = $(data);
                var Fielder = $(d.find('Fielders'));
                if (Fielder.attr('TeamID') == Team) {
                    $('#P').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#C').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 
                    $('#FB').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#SB').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif'); 
			 $('#SS').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#TB').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 
                    $('#LF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#CF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif'); 		 
				$('#RF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif'); 		 
					 
					

Open in new window

New.zip
0
Comment
Question by:powerztom
  • 2
  • 2
4 Comments
 

Author Comment

by:powerztom
ID: 39254371
To clear things up the uniforms represent players in the baseball field Each Team has different uniforms so I want to load uniforms(players) and then load the other teams uniforms at the end of middle inning and then end of inning. the zip has everything.
Thanks for your help
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39254394
I played around with this a bit and came up with the code below. You can take it out of the for loop by the way.
			var d = $(data);
			var Fielder = $(d.find('Fielders').find('Player:first'));
			var Team = $(d.find("Team[ID='" + Fielder.attr('TeamID') + "']"));
			var unfrm = Team.attr('Uniform'); // +'.gif';
			$('#P,#C,#FB,#SB,#SS,#TB,#LF,#CF,#RF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+unfrm);

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39254713
Some more explanation:

* your code was looking for a node TeamID in the xml which doesn't exist.
* the Fielders node does not have any attributes, so I look at the first Player node inside it.
* the if condition was comparing 2 things that would never be the same (empty array and null) but also didn't error.
* the Uniform attribute already contains the .gif extension.
* the last line combines setting all src attributes in one selector because it's all the same image.
0
 

Author Closing Comment

by:powerztom
ID: 39256246
Thanks again this one I was clueless on. But you got it done. Kudos
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now