Events Practice
In this wrap up video we take another peak at events seeing how we could of integrated an event into our code.
Video Transcript
00:01If we wanted to and we wanted to leverage more of that information,
00:05we could have also gone,
00:06we could have dispatched a new event in our on-timer change,
00:10or on our timer complete,
00:12letting our main application know that our timer is complete.
00:15So now you could start another animation that is
00:18the promo that you're trying to work on,
00:20or the banner, or the website promotion that you're working on.
00:24That's all you really need because all you really have to do is just create another dispatcher.
00:29Let's just do it just so you got it under your belt as well.
00:33So if I just even just grab the same dispatch,
00:36and I'm saying dispatch event complete.
00:39So I don't have to change anything in my extends because a sprite,
00:46one of its predecessors is an event dispatcher.
00:49How do I know that? Because we've been working on sprites for quite a long time,
00:53and sprites have a capability of listening to events.
00:55They're interactive objects.
00:57Thus, if they have a capacity of listening to events,
01:00all I really have to do in my onDone function is add another dispatch event,
01:06and just crawl a new event,
01:08and again, give it the event.complete,
01:12close my first bracket, second bracket,
01:15semicolon, and just make sure that I have the event loaded,
01:18and I do because I've used it already before.
01:20All that's really left is in my main app.
01:23I could listen to both of them.
01:25So if I wanted to, I could add an event dispatcher,
01:28we'll add event listener at this time around,
01:31add event listener,
01:35and we want to event and listen to mctimeout.
01:39We want to call on timer done,
01:44and we're only listening to the first one,
01:47but if we wanted to, we could have listened to both.
01:48So I'm going to create a reply function,
01:51on timer done,
01:55it can be an event,
01:56it automatically loaded the event for me because I'm running in CS5,
02:01and now I could just do here a little trace,
02:04we are done, start the animation.
02:10All right, and same thing we could have done to our timer too.
02:13So timer one, let's just fix our error here,
02:17implicit error, no, I'm just going to double click it and see where it takes me.
02:21I try to add an event listener to what?
02:23I tried to add an event listener to my main app.
02:26So what I'm going to have to do is I'm going to ask for my mctimeout add event listener,
02:31because that's actually where I'm asking.
02:32I'm asking my timeout to listen to one of its events,
02:36and by mistake, I completely ruined that syntax
02:39because I want to put here an event.complete as my first parameter,
02:44and my second parameter would be the function that it will be called.
02:47So sorry about that, let's run it one more time.
02:51Our one gets to zero, we should get our, we are done, start the animation.
02:56Just because I ruined the first one, let's do the second one as well.
02:59So second one around, we want to call our mctimeout, mctimeout2.
03:05We want to add an event listener.
03:10We want to tell it an event complete.
03:13And for now, let's just call the same timer done.
03:18And just so we better see it, we'll be able to see it,
03:20let's just notch it down to five seconds instead of so long.
03:24So what we're expecting is after three seconds
03:26to get our first timeout message, and after another two seconds,
03:31another timeout message.
03:33And there you go.
03:34And you could do so many cool stuff with timeouts.
03:37Timeouts are the thing sometimes.
