Rollover and Rollout Events
Looking deeper into Interactive Events as we visit MouseEvent.ROLL_OVER and MouseEvent.ROLL_OUT to create roll over effects with movieclips. We look into getting rid of visual elements in the way of our roll over.
Video Transcript
00:00So the next step now what I want to do is I want to actually add some interactivity to this movie clip.
00:06And to do that I want to do a few things. First of all, I want to go to my home copy.
00:10And let's understand one thing that actually happened right here right now.
00:14So far we've worked in a flat world where there was only one thing on the stage, right?
00:20Which was our movie clip, which belonged to the root.
00:23But now we actually have a movie clip that belongs to our root, which belongs to our main.
00:28And inside of it we have a text field, which belongs to the MC home, which belongs to the main, right?
00:36So it's like a child to child of a child.
00:39Now we could have put in as many elements as we wanted, but this is an important differentiation.
00:43So now we're making it a little bit more advanced. We're going a little a layer deeper.
00:49Very good. So the next step now, because we have all those elements, let's first add rollover event.
00:57So let's go to our MC home. We're going to add an event listener.
01:02And the event listener is going to be a mouse event.
01:05And automatically it added my mouse event, my flash.events.mouse event, because I'm running on CS5.
01:13And then we don't want to do a click. We actually want to do a rollover.
01:18And on rollover we want to call on rollhome.
01:25And we could probably just copy this whole thing.
01:28And instead of rollover this time around, we're going to do on rollout and on outhome.
01:39The last two things we want to do before we publish the file is we want to make sure that we actually have those two methods.
01:44So I'm just going to quickly create a function.
01:47We're going to give it its name in a second.
01:50So we're going to put here just my name.
01:52We're just going to paste it in in a second.
01:54It's going to accept the mouse event.
01:57It's not going to return anything.
02:00And we could copy our name, paste it inside, duplicate this function twice, and change the second one to be on outhome.
02:11And there we go. So right now we have two rollover events.
02:14And if I trace it out right here, we're going to hear we have a roll and here we have a out.
02:25And if we roll over our element, we're going to get a roll.
02:28If we roll out, we're going to get an out, which is fantastic.
02:30Only we have one problem is we really want that arrow to come up here and make it look like it's a real button.
02:36And to do that with a movie clip, by default, it's not set to be true, but it could be.
02:43All we really have to do is go back to our MC home and search for use hand cursor.
02:50But even better, we want to say button mode equals true.
02:54And that should set the rest up for us automatically.
02:57So if we roll over it now, it's going to act as a button.
03:01And that's beautiful. That's exactly what we wanted it to do.
03:04Now you'll notice that we have a little issue because this is still part of our movie clip.
03:09But there's a text field blocking the view.
03:12And we don't want that text field to block the view.
03:15The way for us to avoid this text field from blocking our view is basically telling Flash,
03:21ignore all the children of that movie clip
03:24and treat the whole thing as one when we're talking about a button.
03:27And to do that, it's quite easy.
03:29What we'd have to do is ask our MC home.
03:32And then we're going to set as mouse children, we're going to set to be false.
03:38Basically telling our movie clips that its children aren't clickable or don't react to buttons,
03:46but our MC home does.
03:48Thus, if I run the application one more time, and if we go over that area where the text field is,
03:53we'll see that the text field is not interrupting us and it's not in the way anymore.
03:58Fantastic. So we're miles through already.
04:02So we already have our rollovers and really the next step we want to do is actually change the copy
04:07inside of our MC home text home text.
04:12Let's just for now before we start doing the animation, let's just set it to be directly that home copy.
04:22But what I really wanted to do is I actually wanted to add typewriter to come in and like a typewriter to go out.
04:29All right. But let's just see that it works.
04:31So as we roll over now, it should then the copy should come in and then it should go out.
04:36And that was that easy.
04:38Now the next step that I want to do is we want to add here some sort of way to control time.
04:44Now, even though we haven't worked yet with time.
04:48And you know, it probably makes sense first for us to look at the timeline and see how that timeline works and then go back to this concept of actually interacting with time.
