Ec.remove
Running through all the ways you can remove events using the EventController.rn
Video Transcript
00:00So I've returned our UID back in, I called it UID, and I appended UID into all our add events.
00:07So now instead of just sending the red click, it's going to be, again, UID plus red click.
00:11And same thing for our blue click, I'm adding the UID.
00:15And last but not least, I've added to the controller, the Unremove Events, I passed in a UID.
00:22Now what I want to do is run through quickly on four different types of ways of removing events.
00:29We've gone through three of them already.
00:31The first one was removing an event directly.
00:34So if we would just do ec.remove, we could pass inside the movie clip as the first parameter,
00:39or any event dispatcher, and all the regular parameters that you're accustomed from using with remove event listener.
00:47So this way we would be able to remove one event.
00:50If we wanted to remove all the events of a specific object,
00:53we could send to the remove only the object without any other information,
00:59and it would loop through it and remove all the events associated with that specific object.
01:04If we wanted to remove events based on ID, which we've done that before as well,
01:08then it would remove all items that have that specific ID.
01:12Now the next level that we want to talk about is working with regular expressions.
01:16Now we're not going to go too deeply into the topic of regular expressions in this course,
01:20because we're going to dedicate separate courses for that.
01:24But basically in our scenario, our most simple scenario, which I encourage you to find more advanced scenarios,
01:30but our most simple scenario here, we're going to use regular expressions to search for a basic string.
01:37So we're creating a new regular expression and sending into it a string.
01:41What that does, it enables the event controller behind the scenes to search throughout all the strings,
01:48basically throughout all the clusters, and find clusters that have that string in them.
01:52And if you notice inside of our application now that we have our ID on every single event that we're creating,
01:58everything has that UID.
02:01So by doing remove UID inside of a regular expression,
02:07we're going to make sure that every single event in our project is going to be removed in one line,
02:11versus the line above it would only remove events that are specifically in that cluster that is called UID.
02:19But in this scenario, it's not a cluster anymore, it's a dynamic cluster,
02:22because we're dynamically re-clustering items based on their strings associated with them.
02:28So if I run the application now that we have a regular expression inside,
02:32we're going to see that our buttons are clickable, our rollovers are happening,
02:39but as soon as I click on the green button, it's going to remove every single event in the application.
02:44So as soon as I clicked on the green button, we could see our trace here of the removal.
02:48The green button is not active anymore.
02:50The rollovers are not active anymore.
02:52The clicks are not active anymore.
02:54So every single event, because all the events had an associated UID in them, all of them have been removed.
03:00Now that we see this power, what we could do with regular expressions,
03:05we could actually define ourselves sub-rules.
03:08For example, if we want to disable all, let's say we want to disable all of the blue items.
03:13So let's say we want to send, we could just pass the string blue.
03:17So we could just pass a string right here, and we could pass that string blue.
03:23And now if we run the application again, the blues are working, the reds are working,
03:29but as soon as we click on the green button, everything associated with the blue items is going to be deactivated.
03:35The red items are still going to work.
03:37And now if we wanted to, because so far that's exactly the same thing as we were doing before.
03:45We're basically removing everything related to this for loop.
03:47What if we wanted to remove all the clicks, which would be only all the clicks related to items that have the ID click.
03:54It's not really all the clicks, because we didn't give the clicks ID to our controller.
03:58So our controller itself doesn't have that.
04:00So even though it's a click event as well, we could control it.
04:03So for example, in this scenario, we could say we want to get rid of clicks.
04:06And by saying we want to get rid of clicks, if we run that application again, now we could click on everything.
04:12The rollovers are working. Everything is the same.
04:14But now when I click on the green button again, and I try to click on the red item, the red item doesn't click anymore.
04:19The rollovers are still working.
04:21The blue is not clickable, but the rollovers are still working.
04:24Let me just clear that so it'll be easier to see.
04:28And then again, so the rollovers are working with the clicks or not.
04:32So now we see that with regular expressions, we could be a lot more flexible with the style of our coding.
04:43We could define our rules and kind of figure out, based on the IDs that we give to our events,
04:49we could figure out how do we want to dynamically cluster something into more than one cluster
04:54and remove things in specific times or remove other things in other times.
04:58So the more descriptive your ID is, the more control you have in regular expression on,
05:03trying to figure out when do you want to remove what in any given time without needing to worry
05:07about if they were really removed or they weren't removed.
05:10So this is very much applicable if you have, let's say, a website and that website has five sections
05:16and you want to give a specific identifier for every section.
05:20Then with one line, you could remove every single event associated with a specific section.
05:26Or if you want to disable a menu or if you want to...
05:29There's so many functionalities that you could find with it
05:32and you don't really have a lot of limitations because the limitations are basically your imagination.
05:37Because there's no enforcement inside of the event controller.
05:41All the event controller is doing is validating the clusters
05:46and checking with these regular expressions to see should this cluster be removed now or not.
05:51And enabling you in that way to dynamically create clusters on the fly
05:55or more accurately dynamically remove clusters on the fly.
05:59Now, just as a side note, when you want to add expressions, regular expressions,
06:05you could use the syntax because it's native to Flash.
06:09You could just use the syntax and this would be the exact same thing as the previous line.
06:15And you can see that the clicks are working and now they won't work.
06:25Again, clear. And again, so these are not clickable, but they can roll over.
06:34So that's it about removing and adding events.
06:38In the next video, we're going to touch on logging events
06:42or checking to see if you have a leak in your memory.
