Getting a static instance of a class (singleton) by using getDefinitionByName
I have a ManagerClass
with a Singleton implementation inside, I get the instance by calling ManagerClass.getInstance()
.
Can I get that same instance by just having the class name as a string? I have tried something li开发者_JAVA百科ke:
var theInstance:* = getDefinitionByName("ManagerClass").getInstance as Class;
theInstance.doTrace(); // I get a 1009 error here
well - im dealing with singletons because the application that I'm working on is written in cairngorm, and a whole bunch of things have to be singletons in it. in regards to why I need to "pass the class names" instead of hardcoding them - is for exact that reason - I don't want to hardcode anything in. this application is 5 years in developement, and now would not be good time to switch it to RobotLegs and such.
haha - yea, you're right - i forgot the () after getInstance. Must be the lack of sleep... Now it works!!!!
Sure why not make a Singleton manager (similar to the Flex core mx.core.Singleton class) that registers these classes and handles if they're null.
Similar to here :
http://segfaultlabs.com/devlogs/overriding-default-flexair-mxmanagers-implementations
精彩评论