Sign in to follow this  
RobAU78

[web] Overriding Constructors in ActionScript 3

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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. :/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this