We're not going to have that functionality in this version of AS3.
You'll need to do something different.  Like simulate by creating the
object with a no-arg constructor and then having a well-known function
like "initArgs" which you could call via Function.apply.

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;
}

Matt

-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Vadim Melnik
Sent: Thursday, March 02, 2006 5:28 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How to dynamically invoke AS3 class
constructor ?

This code is similar to "var a:* = new A(1,2,3);" in my original 
post. Arguments count is statically specified at compile time. 
But I am looking for the way to pass different number of arguments 
to constructor at runtime. Arguments type and count are unknown at 
compilation time, that is why someArgs:Array used.

Flex 1.5/AS2 implements class constructor as AS2 Function object and 
we were able to call it like Function.apply(context, args). Now we 
are looking for something similar in AS3...


--
Thanks,
Vadim Melnik.


--- In flexcoders@yahoogroups.com, Alisdair Mills 
<[EMAIL PROTECTED]> wrote:
>
> haven't tried it but maybe try...
> 
> import flash.util.getClassByName;
> 
> then....
> var ClassReference:Class = getClassByName("A");
> var instance:Object = new ClassReference(1,2,3);
> 
> cheers, Al
> 
> 
> 
> On 2 Mar 2006, at 12:25, Vadim Melnik wrote:
> 
> > Hi All,
> >
> > It is going to be easy, but I can't figure the way to implement 
it.
> > We have certain Class object referencing to some class with
> > constructor accepting any ... numbers of arguments. Now we are
> > looking for the way to invoke it dynamically, (something like
> > Funtion.apply does for plain methods). For example :
> >
> > ...
> > public class A {
> > public function A(...args) {}
> > }
> > ...
> >
> > var cls:Class = A;
> > var someArgs:Array = [1, 2, 3];
> >
> > var a:* = new cls(); // <- how to pass someArgs here ?
> >
> > // need the same functionality as
> > // var a:* = new A(1,2,3);
> >
> > And the same question regarding super class dynamic constructor
> > invocation:
> >
> > public class B extends A {
> > public function B() {
> >    var myArgs:Array = [4,5,6];
> >    super(); // <-- how to pass myArgs to parent
> >    // class constructor, like
> >    // super(4, 5, 6);
> > }
> > }
> >
> >
> > --
> > Thanks,
> > Vadim Melnik.
> >
> >
> >
> >
> >
> >
> >
> > --
> > Flexcoders Mailing List
> > FAQ: 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> > Search Archives: http://www.mail-archive.com/flexcoders% 
> > 40yahoogroups.com
> >
> >
> >
> > SPONSORED LINKS
> > Web site design development Computer software development
        Software  
> > design and development
> > Macromedia flex     Software development best practice
> >
> > YAHOO! GROUPS LINKS
> >
> >  Visit your group "flexcoders" on the web.
> >
> >  To unsubscribe from this group, send an email to:
> >  [EMAIL PROTECTED]
> >
> >  Your use of Yahoo! Groups is subject to the Yahoo! Terms of 
Service.
> >
> >
>







--
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



 




--
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/
 


Reply via email to