?
Solved

Loading Images from xml file

Posted on 2013-06-17
4
Medium Priority
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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)
Suggested Courses

762 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