static var inheritance test

by www0z0k
♥1 | Line 29 | Modified 2010-12-17 00:58:09 | MIT License
play

ActionScript3 source code

/**
 * Copyright www0z0k ( http://wonderfl.net/user/www0z0k )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lLor
 */

package {
    import flash.text.TextField;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private var output:TextField;
        public function FlashTest() {
            output = new TextField();
            addChild(output);
            output.multiline = true;            
            output.text = 'parent class static property : ' + Parent.staticVar + '\n\n';
            output.appendText('child class static property before creating first instance : ' + SimpleChild.staticVar + '\n\n');
            var aFunnyWayToInitAStaticVar:SimpleChild = new SimpleChild();
            output.appendText('child class static property after creating first instance : ' + SimpleChild.staticVar + '\n\n');
            output.width = output.textWidth + 20;
        }
    }
}

class Parent{
    public function Parent(){}
    public static var staticVar:String = 'i\'m from parent class';
    public var someVar:String = 'somevar';
}

class SimpleChild extends Parent{
    private static var _staticVar:String;
    public function SimpleChild(){ _staticVar = super.someVar; }
    public static function get staticVar():String{
        return _staticVar;
    }

}