02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

URL Parameters

In this video we learn about URL parameters, what they look like, and how they work. We take a look at the browser and discover they're all over the web.

Video Transcript

00:00So, but let's step in and start seeing our work.
00:02So I've already created a main class, and I'm just going to go into that main class.
00:07That main class is currently empty.
00:09Now, if you haven't really watched the videos about classes yet, if you're watching the
00:13recorded sessions, I do recommend that you first watch them and get used to it.
00:17Obviously, if you're in one of our live events, don't worry about it too much, just ignore
00:21the stuff you don't know.
00:23Because you could also put most of the code that we're going to put right here inside
00:26of our main.
00:27You'll be able to put directly into the timeline.
00:30So you could actually just go select the first frame, go to window, actions, and almost everything
00:34we work on, you'll be able to put directly into the actions and we'll do basically the
00:38same thing.
00:39All right, but we're already working classes, so we're not going to worry about that.
00:43All right, so let's see how do we find those variables.
00:46So the first thing we need to know, even though we never really loaded external content
00:49yet, we have loaded one thing.
00:52We loaded our own application, or that actually loaded for us automatically.
00:56Now, in ActionScript 3, contrary to ActionScript 2, when you load something, it has a lot of
01:01information.
01:02Now, some of the information is actually the content itself, but sometimes there's a lot
01:06of information that isn't the content.
01:09Because one of the main reasons is because they've been added a lot of security features
01:13into ActionScript 3 that didn't exist in ActionScript 2.
01:16It does make things a little bit more complicated, but you don't have to worry about all those
01:20issues until you have to deal with them.
01:23But really, the main reason behind them was Flash matured and it got to a level where it
01:27became a real product that a lot of corporations were using, and they wanted to protect their
01:31data.
01:32Now, one of the ways they protected their data is they put their content into sandboxes,
01:37and Flash basically has to ask, could I watch this content or not?
01:41We're not going to cover that yet in this course, but as you're starting to work with
01:45content in your building applications, you might get errors, and usually those errors
01:49are going to be related to sandbox information.
01:51So what I would say for now, until you're comfortable with security issues, work locally.
01:56Have all your files in the same directory or in the same subdirectory.
02:01That way, when you're working with your files, you won't have any issues that are
02:04related to sandbox security issues.
02:07So if you're loading things from different servers and you're in one server, you're
02:11definitely going to hit some issues until you know how to solve them.
02:14But we're not there yet.
02:15So one of the stuff that we're going to look right now is we're going to look
02:18at that object that has all this information.
02:20Besides security information, it has other things in it.
02:23Now, the way we're approaching every single thing that's loaded into Flash,
02:26everything that is loaded into Flash originates from some sort of loader,
02:30and that loader has loading information, which is called a loader info.
02:34Now, because our root has been loaded, it has a loader info as well.
02:39Now, our main is the root as well.
02:41So if we wanted to, we could have just typed this.
02:43But because we might not be in that main class, you might be working in a project
02:47where we're not there, we're going to go explicitly to our root.
02:50And we're going to type root.loaderinfo.
02:53And that loader info already is giving us that packet of information.
02:57It has security information in it.
02:59It has other things in it.
03:00And one thing that it has in it as well is something that's called parameters.
03:04And really, that's our main focus.
03:05Our parameters, and that sounds familiar, right?
03:08Because if you watched the video about functions,
03:11we said that our function could have parameters.
03:13So this could be one parameter, two parameters, three parameters.
03:17Parameters, in a way, is synonymous to variables.
03:21So if they wanted to, they could have called it FlashVars.
03:23Parameters are, in a sense, variables.
03:27So we have now access to variables.
03:30Now, if we just trace what we have so far, we'll see that our object is empty.
03:34There's nothing in it, because we never really provided any information.
03:38It's an empty object.
03:39Let's say I want to actually create something that's going to be called time.
03:43And we're going to have a time object in it.
03:45Now, right now, there's nothing in it, so it's coming back as undefined.
03:49But let's see, how could we actually add that?
03:51We've worked already with variables.
03:52And I just want to recap that for a second.
03:55In Flash, we created a variable.
03:56If we wanted to create a variable called time, we would create a variable,
04:00set its type, and then set whatever time we want.
04:02Let's say it's going to be 4 PM.
04:05Now, when we're working out of Flash in JavaScript,
04:09a few small things change.
04:11In JavaScript, we would just get rid of the type declaration.
04:15By getting rid of the type declaration, now we have a valid JavaScript code
04:19as far as in the year 2011.
04:22They might change that in a couple of years.
04:24But for now, JavaScript just doesn't accept those extra parameters.
04:29Now, there's another different type of variable definition,
04:33which is called URL parameters.
04:35And you've actually seen them.
04:36So if we actually just go visit Google S3, which is our search engine,
04:41and we're just going to type here a random search.
04:43So I'm going to search for something we're actually going to use soon,
04:47which is going to be the date.
04:48So I'm going to search for a date.
04:50Now, if we look up in our browser, I'm just going to copy the URL.
04:54And I'm going to revisit into Flash.
04:56We're going to see that there's a lot of information in that URL.
04:59And I'm going to just break lines.
05:00So first of all, you see there's a question mark.
05:03And after the question mark, we have here a variable called C partner,
05:07so on and so forth, which is basically my ID at Google,
05:10which enables me to get search results.
05:12And then there's a few other variables
05:14I don't necessarily know what they do.
05:17And then I have here my queue, which is my query.
05:20And I have my SA, which is another something
05:23that I don't really know what it does.
05:25But really, for me, this is the most important variable.
05:27This is what defines our search result in our browser.
05:29So actually, if I went back into the browser
05:32and I decided I want to change the search,
05:34I could have gone directly into the URL,
05:36find it where that queue is, and change it from date to be
05:39NARF, if I wanted.
05:41And now, NARF is going to come up in our search result.
05:44Now, I ran through this really quickly.
05:46But if you notice, in our browser, we had a few extra stuff
05:49that we haven't seen before.
05:51One, we're not using, we're not defining vars anymore.
05:54We're not setting a semicolon after we define them.
05:58Instead of that, what we're doing is we start with a question mark.
06:01The reason why we're starting with a question mark
06:02is so the browser will know that this is the end of the URL.
06:06And from now on, we're going to put in the URLs.
06:10We're going to put in variables, actually, sorry.
06:12And then we start setting variables.
06:14We set a variable name, we give it a value.
06:16And then we give it a value.
06:18So basically, what we're saying here
06:19is we have a question mark, and we
06:21have your key, which is the variable name, and equals value.
06:25The next step after that is, if we
06:26want to create another key, we would use the end,
06:30instead of a semicolon.
06:31And telling us we want this variable
06:32and we want another variable.
06:34So let's say we want a key 2, and we're
06:37going to give it its value.
06:38Now, when we're done, we're not going to put a semicolon.
06:41We're done.
06:41That's all we have to do, just as we've
06:43seen in our Google S3 search.
06:47Very, very simple.
06:47And you're going to see this in a lot of places.
06:49So if you know how to work with variables,
06:51you already know this.
06:52Because all really you had left
06:54is just to connect one more dot, the question
06:56mark and the end.
06:57Now, we're going to see a few things
06:59on how we use this actually inside of Flash.
07:01So we've seen how these URL parameters are built.
07:04And this is exactly the way we create Flash vars in Flash.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!