The problem is not passing the arguments, but how many arguments pass.
I can't use a text file, there I could only store basic types, but not
complex properties nor objects. I think about a dirty solution:
public class ClassFactory{
public static function createInstance(className:String, args:Array):Object
switch(args.length){
case 0:
var clazz:Class = getDefinitionByName(className) as Class;
return new clazz()
break;
case 1:
var clazz:Class = getDefinitionByName(className) as Class;
return new clazz(args[0])
break;
case 2:
var clazz:Class = getDefinitionByName(className) as Class;
return new clazz(args[0],args[1])
break;
....
case N:
var clazz:Class = getDefinitionByName(className) as Class;
return new clazz(args[0],args[1],......., args[N])
break;
default 0:
throw new Error("Too many args. Max is N")
break;
}
}
}
Could you send the parameters/arguments into a text file and retrieve them
from there using loadVars?
John
----- Original Message -----
From: "Miguel Serrano" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, August 20, 2006 6:45 PM
Subject: Re: [Flashcoders] ClassFactory and Reflection in Actionscript
Oh, it's very sad. I developed a script language that can be loaded
and run at runtime in a flash movie.
At this moment I can create instances with no arguments, it's very
impressive, but if I can not pass arguments I can't continue the
project.
>
> > I'm coding an introspection framework for as3, but i have a problem by
> > creating instance at runtime without using new operator.
>
> > I have no problem to create instances of classes with no operators at
> > its construction function. The code is this one:
>
> > public class ClassFactory{
>
> > public static function createInstance(className:String):Object
> > var clazz:Class = getDefinitionByName(className) as
Class;
> > return new clazz()
> > }
> > }
>
> > I need a factory to create instance with an array of arguments, of
this kind:
>
> > public static function createInstance(name:String, args:Array):Object
>
> > any idea??
>
> Unfortunately this can't be done in AS3. I asked this before and the
> workaround suggested by an Adobe engineer was to use a "well known
> initialization method" in your classes and call them after invoking
> the constructor. But this is obviously not feasible if you need to
> work with existing classes and/or want to create a generic framework
> with such capabilities. This is one of the areas where you have more
> limitations in AS3 than you used to have in AS2. I really hope AS4
> will introduce something like: Class.newInstance(args:Array)
>
>
> Jens
> www.oregano-server.org
>
>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com