If you need an object that already exists to be converted into an instance
of the class you can use the XT Prototype class
Prototype.makeInstanceof(obj, Array);
and using Zimmen's suggestion
Prototype.makeInstanceof(obj, _global[tType]);
good luck! you'll find the class at
http://codext.com/code/9
Tyler
On 6/1/06, Zimmen <[EMAIL PROTECTED]> wrote:
Yes it is... so you could use
function makeObject(tType){
return (new _global[tType]())
}
test = makeObject("Array")
as well (this is what the findClass method does eventually. :)
On 6/1/06, Danny Kodicek <[EMAIL PROTECTED]> wrote:
> Thanks, Zimmen and Ian, that's helpful. I'll probably go with Ian's
> solution, which seems a bit more robust (I've been caught out before by
> clever tricks using eval()...)
>
> Danny
>
> ----- Original Message -----
> From: "Zimmen" <[EMAIL PROTECTED]>
> To: "Flashcoders mailing list" <[email protected]>
> Sent: Thursday, June 01, 2006 5:33 PM
> Subject: Re: [Flashcoders] create an object of type defined with a
string
>
>
> > This actually works:
> >
> > function makeObject(tType){
> > var tVar = eval(tType)
> > return (new tVar())
> > }
> > test = makeObject("Array")
> > test.push("foo")
> > test.push("bar")
> > trace(test[0])
> > trace(test[1])
> > trace(test.length)
> >
> > Output:
> >
> > foo
> > bar
> > 2
> >
> > On 6/1/06, Danny Kodicek <[EMAIL PROTECTED]> wrote:
> >> I want to have a function makeObject(tType:String) which returns an
> >> object
> >> of class tType. So makeObject("Array") should return a new Array
object.
> >> Any
> >> good way to do this? I'm sure it's something simple.
> >>
> >> And before you ask, yes, there is a reason why I need to do it this
> >> way...
> >>
> >> Danny
> >>
> >> _______________________________________________
> >> [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
>
> _______________________________________________
> [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
_______________________________________________
[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