Loader
Say hello to the Loader class. This ActionScript 3.0 class enables you to load external visual assets such as images and swfs. Let's take a fast look at the quickest and easiest way to load assets into flash using actionScript 3.0.
Video Transcript
00:00Alright, so the steps that we have to do to actually do this is first of all we're going
00:04to create a new loader.
00:06Now I want to show you the loader for a second, so we're just going to go right back into
00:10Safari and I'm going to go into our Google S3 again and I'm just going to type for, I'm
00:16going to search for loader, not loader info but I just want loader, ah stop that, loader.
00:27Okay, so flash display loader, that's what I want and if we look into it we'll see that
00:32our loader is a display object, alright. Now that's all I really wanted to show that there's
00:38all this stuff that the loader has, we could treat it as a display object. So let's see
00:41how we actually work with this, it's actually quite easy the basics of just getting started
00:45with it. So first of all I'm just going to create, this time around I'm going to create
00:49a private variable and as we said a private variable just no one has access to it besides
00:54our class and I'm going to call it our image one. It's going to be a type of loader which
01:01is a flash display type. Now automatically in flash CS5.5 and also in flash CS5 will
01:09automatically load my import my class but if not you'd have to import space flash.display.loader
01:15and any other element here that is going to be needed throughout our sample. Now in
01:21my main I could start working with my image one. So image one, I first want to create
01:25a new loader, I'm going to open and close my bracket. The next step I'm going to
01:31type image1.load and my load expects two things. One it expects and one is not mandatory
01:38so we're just going to focus on our non mandatory and we talked about that there's
01:42loader context which kind of connects to security which kind of connects to a lot
01:46of other things that we're not going to worry about right now and we're going to
01:49get into them when we dig deeper into loading. But for now we just want to see how could
01:52we load something into our flash application. So when we click on load and
01:57by the way the loader basically loads anything that's visual. So anything that
02:01flash supports that's visual you could use the loader class to load it. Now it
02:04expects a URL request so if you're working in flash CS5.5 or 5 then
02:08you'll see that it's requesting us you don't have to really remember it. The
02:11next step is to actually send it that request. Now we could have set a new
02:15variable in the side and then send it in but really we don't need the
02:20reference so we could create the new URL reference or URL request
02:26directly inside of the new loader. Instead of just sending it a URL then we
02:31could open the bracket and we'll see okay it's expecting a URL. We didn't want
02:34to change anything from its parameters we didn't want to change anything there so
02:37we don't really care about it. So all that's left is all we have to do is
02:40just send our location of our image which is that image 01.jpg and and there
02:51we go oh another bracket and there we go we already loaded the image. All that's
02:55really left for us is to just add it to the stage. To do that we could just type
02:58add child image1. So this is a really really base base base without putting
03:04any any thought into it without adding pre-loaders without making sure that
03:08it actually loads. So really what we're doing is we're adding the loader to the
03:11stage and we're and we're adding the image directly so if we run our
03:16application now we'll see that our image will automatically just appear on
03:19the stage right in the top corner. No pre-loaders no anything.
