[Flashcoders] AS 2.0 constructor inheritance
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? ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] AS 2.0 constructor inheritance
the constructer gets invoked automatically (and its the only function which does all other overrides this is not the case for) but the super class's constructer is being called without arguments so whats happening on a code level is this super(); 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? ___ Flashcoders@chattyfig.figleaf.com 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 -- j:pn http://www.memorphic.com/news/ ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] AS 2.0 constructor inheritance
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? ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] AS 2.0 constructor inheritance
On 8/14/07, Alan MacDougall [EMAIL PROTECTED] wrote: 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? Nope, not a language quirk - your parent constructor doesn't know what parameter it should use for 'clip', so you have to explicitly state it. It's the same in Java, IIRC. Ian ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] AS 2.0 constructor inheritance
Hans Wichman wrote: 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. So if the superclass constructor DOES have parameters, I can't call new SubClass(parameters) without explicitly calling the superclass constructor in the subclass constructor. i.e. this works: // in superclass definition public function SuperClass() { blah; } // in code var foo:SuperClass = new SubClass(); but not this: // in superclass definition public function SuperClass(parameter:Type) { blah; } // in code var foo:SuperClass = new SubClass(parameter); That sounds like a language quirk rather than the nature of inheritance, but I can live with it now that I've identified it. Thanks! ___ Flashcoders@chattyfig.figleaf.com 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
Re: [Flashcoders] AS 2.0 constructor inheritance
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? ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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 ___ Flashcoders@chattyfig.figleaf.com 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