I have a class Sub, that inherits class Super.
In Super I have a protected var with default value set that may be overwritten by Sub in Sub’s constructor.
(eg protected var foo:Number = 5)
In the constructor of Super I want to do a check on that variable overwritten by Sub.
First of all, am I right in the assumption that by default, the constructors of the different inherited classes are run in order of: top ancestor > bottom subclass?
It seems that if I want the subclass constructor to run before the super class I can use the super() method. Is this right?
In my example above I would have to use the super() method in the constructor of **Sub **since I need to set the variable before it is checked in the **Super **constructor.
But this causes a problem.
In the **Sub **constructor, if I trace the protected var the output is its native default value (in this case ‘0’) as if it hasn’t been set yet.
I can change it, and if I trace it again it has the new value.
But when the **Super **constructor runs after that, the variable is reset to what the **Super **class wanted it to be in the first place (in this case ‘5’).
Can someone please explain the nature of this behaviour?
What would you recommend me to do? Obviously I could move the check to some init handler, but for various reasons I’d like to keep the checking in the constructor.