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

forked from: Classes as dynamic objects

Get Adobe Flash player
by makc3d 08 May 2014
    Embed
/**
 * Copyright makc3d ( http://wonderfl.net/user/makc3d )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pBeH
 */

// forked from Glidias's Classes as dynamic objects
package {
    import flash.display.Sprite;
    import flash.display.DisplayObject;
    import flash.text.TextField;
    
    public class ClassesAreDynamicObjects extends Sprite {
        
        private static var PRIVATE_VAR:Number = 999;
        
        public function ClassesAreDynamicObjects() {

            var field:TextField = new TextField();
            field.autoSize = "left";
            addChild(field);           
         
           var anonymous:* = ClassesAreDynamicObjects;
            anonymous["PRIVATE_VAR"] = 123;  // it seems the compiler doesn't treat anonymous as really anonmous under this scope, writing to my own private namespace
            field.appendText(",\n"+ClassesAreDynamicObjects["PRIVATE_VAR"]+", "+PRIVATE_VAR + "<- LOl. what the heck. I replaced my own private static var PRIVATE_VAR");
            
            new Test(ClassesAreDynamicObjects, field);
            field.appendText(",\n"+ClassesAreDynamicObjects["PRIVATE_VAR"]+", "+PRIVATE_VAR + "<- LOl. what the heck. It is still 123");                              
        }
    }
}


class Test {
    function Test (c:*, tf:*) {
        tf.appendText("\n123 == " + c["PRIVATE_VAR"]);
        c["PRIVATE_VAR"] = 456;
        tf.appendText("\n456 == " + c["PRIVATE_VAR"]);
    }
}