I have a class that is currently pretty dirty / repeating:
public class AvFramework extends Object
{
private var _handler:AvHandler;
private var _keyboard:AvKeyboard;
private var _manager:AvManager;
public function AvFramework()
{
_handler = new AvHandler();
_keyboard = new AvKeyboard();
_manager = new AvManager();
_handler.framework = this;
_keyboard.framework = this;
_manager.framework = this;
}
public function get keyboard():AvKeyboard{ return _keyboard; }
public function get manager():AvManager{ return _manager; }
}
This class will have to use more and more classes, and I really don't want to have 3 huge lists for this, as mentioned above.
Is there a way to do this dynamically - perhaps using getDefinitonByName()a line loop to represent the classes I want to create.
I also want the properties to be read-only and accessible through framework.myDynamicVarHere.
I think something like that:
- I am creating a list of classes in which I want to instantiate, paired with the name of the variable they should be accessing.
- I need to make a class
dynamicso that I can install vars viathis["var"] = new Blah();
A quick snippet of where my thoughts go:
var required:Object =
{
keyboard: "avian.framework.background.AvKeyboard",
manager: "avian.framework.background.AvManager",
handler: "avian.framework.background.AvHandler"
};
var i:String;
for(i in required)
{
var Req:Class = Class(getDefinitionByName(required[i]));
this[i] = new Req();
AvFrameworkObject(this[i]).framework = this;
}
, .