Compiler Error 1203

I ran into this one last night while working on the new site for RockfordGrill.com. I have to admit this one stumped me and I had to do a whole bunch of digging around to figure it out. Once I discovered the issue, it made perfect sense but at the time (about 1:30am) I was at a loss.

1203: No default constructor found in base class.

The Situation

I had written a pretty complex class (which required 3 arguments) to create the content sections for the website and wanted to extend it for a section that required additional elements. So I created the subclass that extended the base class and tested it which fired the error above. Below are 2 examples classes that illustrate what I was doing:

BaseClass.as

package{

import flash.display.Sprite;

public class BaseClass extends Sprite{

public function BaseClass(arg1,arg2,arg3){

trace(arg1);

trace(arg2)

trace(arg3)

}

}

}

SubClass.as

package{

import BaseClass;

public class SubClass extends BaseClass{

public function SubClass(){

}

}

}

WTF!?

Typically when you extend a class you the constructor of the subclass automatically calls the constructor of the super class it is extending. In this case no dice – so why?

Well according to the documentation you must implicitly call the constructor of the base class with a super statement if the base class requires 1 or more arguments. My base class took 3 – so that was the issue which as I said makes sense after a bit of sleep and a coffee.

The Fix

In the constructor of the subclass I added a super statement with the arguments.

See below for the updated SubClass.as

package{

import BaseClass;

public class SubClass extends BaseClass{

public function SubClass(){

super(arg1,arg2,arg3)

}

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *