> public function createInstance (className:String, args:Array) : Object {
> var myClass : Class = getClassByName(className);
> var inst : Object = new myClass();
> inst.initArgs.apply(inst, args);
> return inst;
> }
Yes, that would be a workaround if I have complete control over the
classes I work with, but that is not always the case.
In AS 2 I work with a configuration framework inspired by Spring. I
can do stuff in XML config files like this:
<object id="myObject" class="myPackage.MyClass">
<constructor-args>
<string>arbitrary string</string>
<boolean>false</boolean>
</constructor-args>
<property name="duration">
<number>5000</number>
</property>
</object>
Currently it would be impossible to port that to AS 3 which would
really be a step back (which is sad because otherwise AS 3 is so much
nicer than AS 2). In AS 2 I use a simple hack to implement how
the <constructor-args> are applied:
public static function createInstance (className:String, args:Array) : Object {
var clazz:Function = eval(className);
var obj:Object = new Object();
obj.__proto__ = clazz.prototype;
clazz.apply(obj, args);
return obj;
}
I really think something like Class.createInstance should be in the
spec, it is quite important for generic frameworks. Couldn't you
Adobe-guys push that? ;)
Ok, I will file an enhancement request...
Jens
www.oregano-server.org
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/