Jump to content
  • Advertisement
Sign in to follow this  
RobAU78

[web] Overriding Constructors in ActionScript 3

This topic is 3173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!