Razorberry’s Adobe Flash Blog

June 14th, 2005

AS2 Lazy Construction Weirdness

Posted by Ash in Actionscript
Actionscript

Update: (See comments) I completely forgot that subclasses call the superclass constructor by default. Don’t I feel dumb right now. But I’ll leave this post here as an exercise in pointlessly using __resolve to decorate classes on-demand. :D

Consider this strange example. I have a class, called Widget. This class contains core code for handling all kinds of Widgets. Other people will be extending this class to create their own varieties of Widget (BendyWidget, SpinnyWidget).

Now, in my core class I want to add EventDispatcher functions, so I can dispatch certain core events like “exploded”.
Cool, I’ll just put the code in Widget’s constructor function and everything is good, right?

Now what if my Widget constructor never gets called because I can’t rely on the creators of BendyWidget to call super(); in their constructor function.. how can I guarantee that my class will have the event dispatcher functions?
(more…)

Macromedia XML News Aggregator