Lol that doesn't really work, well it does but only in limited cases.
Because it requires for you to actually left click on the channel window before closing it.
Try it like this: go with your mouse over a channel button, and right click and press close. Active event won't have triggered for that window, and the $lactive identifier won't be filled with this window when you click another window, so nothing will happen.
Also if you programmatically close windows, it won't happen either. For example: connect to a server, join channels #one and #two. Then disconnect from the server, and then type /part #one. The channel window will close, but once again, active event didn't trigger, so nothing happens.
Anyway, that code was for you, so you should just use whatever you please, if you rather go with the active event, then thats your choice of course.
Greets