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

Cleaning up

Its very important to clean after ourselves so in this video we clean up our events when we are done working with them.

Video Transcript

00:00So we know that our load has completed and really the next step is we want to actually get its width and height
00:05Very very easy. So before I do that it we're doing something a little bit
00:11Improper now, we're not putting all the events that we should we don't really care about everything
00:15you know because we want to keep it simple in this in this class, but
00:19One of the stuff we want to do is when we add events we do want to get rid of them
00:23Okay, and we do have a separate class about removing events
00:26But when we complete something we know it's already done and when it's done
00:30We want to remove all those events the easiest way to do that is we could just copy everything in there
00:35Right and on complex. We know when completed we don't need these events anymore and we could just remove
00:42Instead of adding and that would just do the trick that would remove all of our events that we don't need anymore
00:47But because I like being a little bit more fancy. I want to show you a different way of doing this
00:52Which is very similar. I really really don't like using and you should when you get more comfortable as well
00:59You should try to avoid using hard-coded values inside of your events because now we're loading image one
01:04But when we learn load image two would be nice if we could use the same function to load image two as well
01:10All right, so let's see how we could do this. First of all, let's see what our event contains
01:14So if I go to my event and I type e dot target our event our target. Let's see what is coming back
01:20We'll see that the value that's coming back in our trace when the event is loaded and completed
01:25We're getting our loader info and that loader info is of our item that was loaded which is basically our content loader info
01:33So I could instead of typing
01:36Instead of typing image one dot content info I could type e dot target
01:40E dot target and that would already automatically get me to the element without actually explicitly calling it in its name
01:48Okay, let me see if that makes sense. Okay. Do you guys are you guys with me still?
01:54Does that um
01:56Kind of right. It's a little bit more confusing. That's it
01:59That's really where you know, we're where we're stepping in at this stage
02:03Well, you already know all the basics now the next step in in your I would say maturity as programmers is
02:10Starting to abstract ideas. I've been talking a lot with this with Adam privately and emails because I'm helping him a bit with this game
02:18What you really want to do is
02:20Every time you look at something you want to try to figure out. Okay, how can I say this without explicitly saying it?
02:25But it's not explicitly saying it the event is information that send to my my event when it returns
02:31It sends some information in that information that sends our target, which is basically what called it and keeping it simple
02:38It's what actually called it. So what did called event what triggered the event?
02:43What started the event is this because this is where we added our add event listener
02:48That's when we go to our e dark target. We're actually getting whoever initiated our event listener
02:54Okay, does that does that sit better?
03:01Okay, good and you know what you don't have to work with it right now
03:03But I do recommend slowly slowly stepping out of working directly with things
03:07Because one of the next things that I'm going to do and let's do it
03:10One of the next things is instead of adding the loader into the stage
03:14What I want to do is I want to actually add the actual
03:18Visual element. So if I do here again another trace and I go to e dot target
03:24And I'm going to go to the loader info documentation for a second just to show you
03:29We're in our loader and we're going to look for our loader info
03:33Or we could go back back into our Google s3 and just add your loader info
03:40And go into the loader info object and we'll see that one of the properties of the loader info is going to be the content
03:48Content here we go, which is going to be a type of display object. So all I have to do is dot content
03:56And now we're actually accessing the thing that's inside of the loader
03:59So when the load it will be completed we're gonna have access directly to that bitmap
04:04Okay
04:06Now if we wanted to we could have asked that bitmap
04:08But we're gonna keep the image one for now
04:10but that was just for the
04:12For example because right now we're adding more than we actually need to we could have such as we're loading another
04:17So if we didn't have to use our loader as our visual element as well
04:20We could have used it just for the loading process and then discard it, but we're gonna keep it

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!