RollOut ENTER_FRAME logic
We hope you took a small break and tried to figure it out on your own. In this video we will solve the logic to complete our animation.
Video Transcript
00:00Okay, so we have our rollover working and the next thing we want to do is add our roll out animation.
00:06To do that I'm going to create another enter frame so I'm just going to copy paste because I'm a lazy programmer.
00:11And I'm going to copy from our on roll home to our on roll on our out home which is our roll out motion.
00:18And we want to add a new enter frame and this enter frame we want to call on out enter.
00:24And we could save that.
00:29And I'm just going to duplicate this whole function here on roll enter and change the name on out enter.
00:37Alright, so I'm just being quick about it.
00:41And obviously we want to change the logic that's going on here. We actually want to do the exact reverse.
00:45So first of all, let's start from our if statement.
00:48If our copy equals nothing that means that our event has completed, right?
00:52So then if our copy equals nothing then we want to get rid of that enter frame.
00:59At the same point we want to make sure that as soon as we rollover we get rid of any enter frame that was related to on out enter.
01:09Okay, so now we took care of all of our logic related to making sure our events are running.
01:18So the first step we did is when we rollover we start up our enter frame for our on roll and get rid of our on out.
01:27And same around when we're going out we're going to get rid of our in enter frame and we're going to call our out enter frame.
01:34Alright, so it's exactly the opposite.
01:36Now the only thing that we're missing that's wrong at this point is we want to change our copy right here.
01:41The easiest way probably to do this is if we just, we'll just put a new value into our text field.
01:48And I'm just going to delete all of this copy.
01:53So I'm going to take it a new text and what I want to take to this text, I want to take the length of this text.
02:01And if we go into our copy which was again, what was it called, it was home copy.
02:07Let's look for a method that would be good for this.
02:10So we want to probably slice or something like that and here we go, we could see that we have a slice.
02:15So we have a method called slice.
02:17It's the first parameter we want to start from position zero.
02:20And then the question is how long do we want it to be?
02:22We want it to be one less than what it was before.
02:25So the length of a little bit less than what it was before again we would approach our text field and just ask it how long it is.
02:32So I'm going to ask our text field dot length minus one.
02:37And this way I'm actually cutting out every time one less one less until I'm cutting 00 which would actually produce an empty string.
02:46And when I create that empty string, it's going to find a line 43 that it was an empty string and it's going to stop our event listener.
02:53All right.
02:54So now let's just add here our little trace so we could see that this one is on out.
02:59We're going to make this a minus on and we're going to make it a plus.
03:03And let's save this and run it.
03:05And let's see if our animation is working as we expected it so we could throw this a little bit into the center.
03:10And if I roll over, my animation comes in really nicely.
03:14And when I'm coming out, I could see that I have here some sort of issue.
03:17So let's see what's wrong.
03:18First of all, even when I roll out, it's an endless loop, which probably indicates to me that something here is not working.
03:26The logic set that I put in my enter out is just not not panning out.
03:30It's not logical.
03:32So let's try to figure out what's going on here.
03:35Probably the next logical step is to start making some traces until we see what our issue is.
03:41So to figure out that issue, we're going to put here a little trace.
03:45And I'm just going to trace out what the information I'm saying to slice.
03:49Because it looks like even though after we get to zero, it's still continuing onwards.
03:55OK.
03:56And let's see why that's happening.
03:59Let's see if it's actually being called even when we get to a level of minus one.
04:04And we could see that it's still being called at minus one, which is our problem.
04:08And if it's being called at minus one, that means even though it gets to zero, our if statement is not correct.
04:15And if you look again at line 43, we'll see that, OK, this is why.
04:19Because our home copy never changes.
04:22Our if statement that we actually wanted to ask for was for our text field.
04:26So the value of our text home dot text was the value that we actually wanted to test.
04:31So if I select that, I save that, and I run it one more time,
04:36I'm going to see that it's working.
04:39All right.
04:48So we see now that it's working.
04:51We see that it's not going into an endless loop.
04:53We could see that our traces are only happening once.
04:55So I think we just did a good job here and our animation is complete.
