[web] Overriding Constructors in ActionScript 3

Started by
2 comments, last by Stelimar 14 years, 1 month ago
So I've decided to delve into web-driven game development on the side, using ActionScript 3 (specifically the Flex SDK). This tutorial talks about overriding constructors in AS3 classes. However, I'm a bit confused by what effect this actually has. According to this, the default behavior for a subclass's constructor function is to automatically call its superclass's constructor first. So my guess is that, if you override the constructor, that default behavior doesn't happen. Does anyone know whether I'm right? Thanks!
Advertisement
So no one around here knows?
Quote:Original post by RobAU78
So no one around here knows?

No. ;)

I have to say that this is the first time I've seen this uhm, construction. You're right about the default behavior, but I'm unsure what behavior overriding the constructor would yield. I have never seen it being mentioned in documentation. Have you tried it out?

I quickly glanced over the tutorial, and from a software design perspective, I'm not even sure why it is desirable or even necessary to extend an existing class and override its constructor and from what I can see, pretty much all its methods. The inaccurate descriptions in the text don't help here either. :/
Quote:Original post by RobAU78
According to this, the default behavior for a subclass's constructor function is to automatically call its superclass's constructor first. So my guess is that, if you override the constructor, that default behavior doesn't happen. Does anyone know whether I'm right? Thanks!


You are correct. When your class is compiled, the default constructor is something like:

public function ClassName():void {	super();}


The super() statement simply calls the superclass's constructor. If you define your own constructor, it will not be called. However, if you would like to, you can call it yourself by simply adding super() as the first line of the constructor.

This topic is closed to new replies.

Advertisement