In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

static var inheritance test

Get Adobe Flash player
by www0z0k 16 Dec 2010
    Embed
/**
 * 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;
    }

}