Solved

Loading Images from xml file

Posted on 2013-06-17
4
347 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DTD and JAVA versions 1 26
need help with share buttons 11 65
Video Tutorial help 2 37
How do I update select listbox after search 2 21
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

679 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