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

Preloader

Creating our prelaoder for our newly loaded image using the ProgressEvent.PROGRESS event.

Video Transcript

00:00So after it finishes loading let's just add it right into the stage. So we could just do an
00:04add child and we could just go to our image one and just add image one right into the screen.
00:09And now what I want to do next is I want to create that you know talking about pre-loaders.
00:13Let's create a really really really quick very very basic pre-loader just for this
00:17image one that's being loaded. Now when we were looking at we saw in our content loader info
00:22add event listener. We saw that one of our options was a progress event. So in our progress event
00:30it automatically is adding our progress event and I'm going to say on progress and I'll create
00:37another private function on progress and it's going to have a type of event of progress event.
00:49It's not going to return anything as always. Let me just make our screen a little bit bigger.
00:54All right so now let's see what information could we grab out of our load of progress. First of all
00:58we could get the bytes loaded and we could also get the total bytes and we're already really really
01:04close to creating a pre-loader. All we have to do is the on progress. So if we just run this
01:08just for a second to see it running we'll see that our information is slowly loading adding in
01:13adding in. Now the next thing that we want to do is when it's done when it'll finish loading then
01:19it'll show our application but we actually want to get our we actually want to get a percentage.
01:24To get a percentage all we really have to do is divide how much was loaded by the total
01:29and then we're going to get a value between zero and one. So already we're closer and we're ready
01:34getting this value that's growing over time. Now all that we have left to do is actually
01:38create a really really simple pre-loader and pre-loaders are really really simple. So let's
01:43see how they're loaded and in a second we're going to answer questions just in a second.
01:47So I'm just going to really really quickly just create a movie clip. I'm just gonna not do that
01:52f4 just so we could get our tools and I'm going to create we're just going to create a little
01:57pre-loader. It's going to have an outline and this is going to be our movie clip. Now our
02:04not going to be very pretty but you guys could make it pretty. We're going to modify it and
02:08convert it into a symbol and I'm just going to call it MC pre-loader and we can call this MC
02:16pre-loader for our movie clip itself as well. I'm going to double click into it because I want
02:20to get only the bar itself. I want the frame what I actually want to do is I want to get this
02:25area to fill in and because I have your radio frame I'm going to leave the frame where it is
02:29and I'm just going to let this fill in and obviously you could have done whatever you
02:32wanted. So I'm going to take just the content I'm only going to select the content I'm going to
02:36let's zoom in to make it easier to see. I'm only going to select the content itself
02:41and I'm going to modify that convert it into a symbol. Now one thing that I want to make sure
02:46is that my I'm aligned to the left so when I animate when I animate it's going to animate
02:51that way and it's not going to be animating in the center or in the right and we could call
02:56this our bar and I'm going to call this movie clip a bar as well and now when we animate our
03:03element we're going to get it to move from here to there. So what the last thing that's left
03:08from us is to actually animate it. So I'm going to leave my pre-loader on the stage.
03:13The reason is I don't really care that it's on the stage is because when the pre-loader is done
03:18we could or remove it if we wanted to or the image is going to be on top of it anyways.
03:23All right so we got our pre-loader here it's called mcpreloader
03:27and now in our progress bar we could go and say mcpreloader.bar.scalex equals
03:40that value that just came back because scale x accepts the value between zero and one.
03:46And that's all I had to do to create a very simple pre-loader. So pre-loaders are very very easy
03:50so let's run it and see what happens. So first of all it starts loading loading loading loading
03:55and when it completes loading our image is going to be automatically added onto the stage.
04:01Now we have issues still that we want to make sure that our image is not going to be
04:04this weird we wanted to align it in the stage so we're going to do that as the next thing.
04:07I first want to go back to the questions and see if there's any issues or questions.
04:11So is there any questions concerns issues or is everyone happy so far?
04:21Fantastic. All right so Alex by the way are you okay? No no I don't think so.
04:32I think it's just because Alex is newer on the site so it's a great way to just see if
04:36he's okay with this and it's okay if you don't remember it by heart. The most important thing
04:42and completely understandable what I would love to know is if I send you the source files
04:46and you're looking at them and all you have to do is load another image
04:50that you're capable of doing that and such as changing the animations of the pre-loader and
04:54stuff like that. So even if you can't build it from scratch because you just started working
04:58inside of Flash I want you to know that well you don't have to remember how everything is done as
05:03long as you're looking at this now and when you download these files you can use it in your work
05:07and it makes sense. Okay and obviously if it doesn't or when it doesn't then just
05:12send us an email go on our form whatever and just let us know and we'll definitely help.
05:17All right but completely understandable because Danny and Carol have been around for a while so
05:23they've seen most I think most if not all of the videos on the site already or a nice big
05:28portion of them. All right so the last thing that I want to do with this sample and that's going
05:33to be a ramp for our course is what I want to do is I want to actually take that image when
05:37it's loaded and then get its width and height and align it to the stage and figure out how
05:41could we make it in nice. Yeah Alex you're doing fantastic Danny when he started he was new
05:50Carol was new and quite a lot of other so you just give it a month or two and you'll see that
05:53you'll be swimming in it like everyone else. I think that's a British phrase to say no because
06:05I wouldn't say that. All right so let's get let's get back to wrapping this thingy.

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!