We will be undergoing scheduled maintenance on May 20th, 2013 at 02:00 GMT.
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Now, we can clean things up a little bit more and do some more restructuring and talk about how we might want this code to be structured for various purposes and the first thing that I'm going to do is I'm going to open that file that I'm using for the data, which has this two values in it. It's an XML file and I can come in here and look at the source of this file because the browser is showing it to me as two numbers, but I can see what I've got here and this is the XML. And I'll take a look at the XML and I will make some changes to it. This one I really don't care about, I'll hide that Ôcause I'm interested in this and you can see that what I did when I run it is I picked up this, the Canadian dollar number. So, let's go back and take a look at the code and see how we can clean it up a little bit and make it more a general purpose. The first thing is to take out this alert, which I don't need. I left it in there as a comment in case we had to go back and do some debugging and we don't need that, I'm going to take out that blank line and look up here, I think things are pretty much as they should be, but let me draw your attention to the fact that I've put the end location of this function up here in the load handler and I said, whenever the app starts up and we load it, we are going to execute this. We are going to go out execute the XML Request, create it, execute it and put its value in this field called Currency Result and we're putting in the value. That's what we wanted to do here because I wanted to show you how to do that, but maybe that's not the right way to do it in all cases. It's the right way when you want to use XMLHttpRequest to go out and get some value, some data from somewhere out there on the Internet and do something with it when the app starts up, but sometimes you want to do something different and sometimes you've seen cases where we've gotten all of the items in an RSS feed for example, but here I've hard coded that fact that I'm getting Canadian dollars here and I'm putting them in the field called Currency Result and I'm going to start by renaming that field. We'll call it Canadian Rate. That's the field I'm interested in here and I'm going to have to make a change down here. I'll do it right now so that I'm putting the value that I've retrieved for the currency code CAD in a field called Canadian Rate and why am I doing that? Well, you probably can figure out that what I want to do is I'm going to come in and add another field. I come in to the library and what I want is another text field and I'll put it over here and notice how the guides help me align things. I'll move this aside. We'll get to this shortly. This is called Canadian Rate and this one is going to be called Euro Rate because that happens to be the other currency that I have in the file. Now, that's very good. I can go out and get both of those or either one of those and put them into the correct field, but while I'm at it, what I better do is label them so I'm taking text, not the text area or text field but text and putting it here. Now, I want to check here with the inspector and I'm looking at, I'm here in a 10 point font. Over here, this is going to look better right next to it if I also make it a 10 point font and let me choose Arial. Let me come up a little bit for that one and I think that that will look good and let me and I'll call it Canada. Now, I'm going to copy this or just duplicate. I was going to Copy and Paste that. I can duplicate it, move it down here and notice how as I move things around in Dashcode, everything is centered with those guides and I'm going to call this Euro and I'll just do a reality check to make certain that everything is in the right place and I could change these Canada label, Euro label. So, now, what I can do is I've got these two fields here and what I can do is leave the call up here and setup XML Request, but I'm going to make, the first change that I'm going to make is to go out and call the XMLHttpRequest twice, once to get the Canadian exchange rate and then to get the Euro exchange rate and I'll fill in the appropriate fields then we're going to do it yet another way.
| Course: | Developing iPhone Web Apps |
| Author: | Jesse Feiler |
| SKU: | 34075 |
| ISBN: | 1-935320-89-0 |
| Release Date: | 2009-12-31 |
| Duration: | 8 hrs / 103 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |