Solved

Loading Images from xml file

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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
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…

717 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