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

Packages Part 1

We look into packages again but this time stop and explain why we use them.

Video Transcript

00:00Now, I'm just going to say a few more words, just about the basics in here.
00:06So first of all, we have here a package, and the package really, almost 99% of the time,
00:11we didn't really put anything in the package, and we just put everything in our root directory.
00:16And that worked for us so far.
00:18But now that we're starting to create object-oriented programs, we're going to start to have a
00:22lot of classes.
00:24And as we get a lot of classes, we are going to need to be able to recognize between
00:28them, and to make it easier for us, enter our brain, I would say, to be able to differentiate
00:33between them.
00:34Now, in the beginning, you might not have that many classes.
00:36You might have four or five classes, right?
00:38So you might not need to break them into folders, but it's a good practice to start putting
00:42them into subfolders for two reasons.
00:46One is you might be leaning on open source things.
00:49We already started playing with that when we looked at TweenMax, and there's a lot
00:53of other open source things out there that are really, really useful.
00:56Now, they might have another class that's called main as well, which might be a problem
01:00for us, right?
01:01Because if we put them all in the same directory, or we put them all in the same place, and
01:05this is not our...
01:06Let's go into our folder right here.
01:09All right, so we're in our folder, and we can see that our main is sitting in the
01:17same place.
01:18Now, what happens if we had another file that was called main?
01:21We would have a problem.
01:22It would be hard for us or impossible for us to know, okay, so when you say main,
01:26what do you actually mean?
01:28And that's where really, really packages come into the picture.
01:31And I know we're taking this in a little bit of a weird structure, because we already
01:35did this before, right?
01:36So we're really just breaking it apart to make it really, really crystal clear.
01:41So we have a package, and from now on, we don't want to put anything in the
01:45main package, because it's just confusing.
01:47As we get more applications running, or even...
01:50I could give you an example from just a project I was working on two, three weeks
01:53ago.
01:54The exact same application.
01:55It was just a video player.
01:57Now, there were some changes between Flash Player 9 and Flash Player 10, and we
02:02had to create the exact same player, same visual, same code, almost one-to-one,
02:06besides a few little changes.
02:08All the problem was is that we had to create one version for Flash Player 9,
02:12because we had to support older versions of Flash, and we had to create
02:15a new version for Flash Player 10 plus, so we had to create two applications
02:19that were exact same thing.
02:20Now, the solution that we did for it was we created the exact same code,
02:24we just duplicated it, and then we just gave it two different package names.
02:28So we'd have one package that was Flash 9, FL9, and one was FL10.
02:34To make it easy for us to use the exact same code all over, just using a few
02:38changes in just packages.
02:40All right, so let's look at the basics of how do we create a package.
02:46So we've done it before, but we're going to do it one more time.
02:49A standard in the industry is really, you always start with your domain.
02:54And then opposite domain.
02:55So if we look at our website, if I just jump into our website,
02:59our domain is everythingfla.com, I'm assuming your domain is different.
03:03So we always start from the .com, and then we dig deeper in.
03:06The reason why is just it's just from organizational perspectives.
03:09When you download all these open source things, they're going to start
03:12in the same structure also usually.
03:15And then it makes it easier for you to organize your code
03:17so you could find it more easily.
03:19All right, so we have your .com folder, and we're going to create
03:21a new folder inside of this folder.
03:24So I'm going to go inside of it and create a new folder.
03:26And that new folder is going to be everythingfla.
03:28And I like keeping everything lowercase when I'm working with package names.
03:32Now, the reason why I like putting all my packages in lower name,
03:37and I do recommend that you do the same thing.
03:39It is kind of a standard, you could do camel cases in package names,
03:44but I personally recommend keeping it all lowercase.
03:47Now, why do I prefer keeping it all lowercase?
03:50And let me, I'll just throw it out as a question.
03:51Even though we didn't really, really talk about it,
03:53but let's see if you guys have an idea of why, well, not necessarily,
03:57there is not a specific importance for that specifically to be lowercase,
04:00but the idea behind it, we really want to be able to separate between things.
04:05That will be the hint.

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!