setting actionscript 3 superclass variables

Posted by jedierikb on Stack Overflow See other posts from Stack Overflow or by jedierikb
Published on 2010-04-05T17:42:26Z Indexed on 2010/04/05 18:13 UTC
Read the original article Hit count: 235

Filed under:
|

In AS3, if I have a class such:

public class dude
{
//default value for a dude
protected var _strength:Number = 1; 
public function dude( ):void
{    super( );
     //todo... calculate abilities of a dude based on his strength.
}
}

and a subclass

public class superDude extends dude
{

public function superDude( ):void
{
   _strength = 100;
   super( );
   trace( "strength of superDude: " + _strength );
}
}

This will trace strength of superDude is 1. I expected the variable I set in the subclass (prior to calling the superclass constructor) to remain.

Is there a way to assign class variables in subclass constructors which are not over-written by the superclass construtor? Or should I pass them up as constructor variables?

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about flash