One of the most common questions I am asked is also one of the biggest problems I see in code as I read it: lack of optimization. I often have people asking questions about how they can consolidate the generic actions they want multiple objects to have access to perform without duplicating the code. In Actionscript, just like any other coding language, the duplication of code is typically a red flag that you are doing something wrong. No, not wrong in the sense of broken, but wrong in the sense of best practice and code optimization. It is much easier to have one handler function to debug and keep up than to have that same handler individually executing in a dozen different class objects.
Quite possibly the single most useful thing I have discovered in optimizing some of the graphical effects I use over and over again is simply making use of the event object in my callback functions. When you attach an event listener to an object and the event is triggered, the event passed into the callback function has a target attribute that is a reference to the object which initially triggered the event. Accessing the object this way lets us generalize handlers (such as a fadeOut function) that will consolidate our code and give us uniformity in execution.
Continue reading