Interesting thread, Alan!
What is ECMA Specification saying to that situation?
Matthias
slightly OT, but I have noticed some time ago, that Flash IDE claims
the super() call to be the first line in the constructor of the
extending class. But I noticed to the same time, that when compiling
with mtasc this is not true and even with Flash only claims (warning
only) but does allow this.
Example:
class Bird
{
public var name:String = "bird";
public function Bird()
{
trace("--> "+name);
}
public static function main()
{
var b:Bird = new Bird();
var e:Eagle = new Eagle();
}
}
class Eagle extends Bird
{
public function Eagle()
{
name = "eagle";
super(); // this is not allowed, but works
}
}
traces:
--> bird
--> eagle
2007/8/14, Hans Wichman <[EMAIL PROTECTED]>:
> Hi,
>
> when the superclass has a default contructor without parameters, there is no
> need to call it explicitly.
> I'd like to turn it around though, no matter what or how you have defined
> them, always call them explicitly for clarity's sake and self documentation.
>
> greetz
> JC
>
>
> On 8/14/07, Alan MacDougall <[EMAIL PROTECTED]> wrote:
> >
> > Compare these two situations:
> >
> > class SuperClass
> > {
> > private var list:Array;
> >
> > public function SuperClass()
> > {
> > list = new Array();
> > }
> > }
> >
> > class SubClass extends SuperClass
> > {
> > // when instantiated, the list variable is automatically initialized
> > }
> >
> > This is as it should be. The superclass constructor is executed when the
> > subclass is instantiated, as long as the subclass doesn't override it.
> >
> > class Button
> > {
> > private var clip:MovieClip;
> >
> > public function Button(clip:MovieClip)
> > {
> > clip.onRelease = Delegate.create(this, handlerMethod);
> > }
> > }
> >
> > class SpecialButton extends Button
> > {
> > // does not override the superclass constructor
> > }
> >
> > In this case, code such as "var foo:Button = new SpecialButton(clip);"
> > does NOT execute the superclass constructor. Instead, I need this:
> >
> > class SpecialButton extends Button
> > {
> > public function SpecialButton(clip:MovieClip)
> > {
> > super(clip); // now it works
> > }
> > }
> >
> > My understanding of inheritance is that I should not need to explicitly
> > call the superclass constructor as long as I'm not overriding or
> > extending that method of the superclass. What gives? Is it a language
> > quirk?
> >
> > _______________________________________________
> > [email protected]
> > To change your subscription options or search the archive:
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> > Brought to you by Fig Leaf Software
> > Premier Authorized Adobe Consulting and Training
> > http://www.figleaf.com
> > http://training.figleaf.com
> >
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com