yeah, that works, but you are calling the static create() method through the name of the class itself. Say I have a number of classes (MyClass1, MyOtherClass, AnotherClass) and I be able to alter which class to call the create method on. I'm thinking there's got to be a way to do something like:
//set the name of the class to call the create() method on var classToCall = "MyClass"; _global[classToCall].create(); //change the name of the class to call create() on classToCall = "MyOtherClass"; _global[classToCall].create(); again classToCall = "AnotherClass"; _global[classToCall].create(); On 12/29/05, JesterXL <[EMAIL PROTECTED]> wrote: > > Hrm... how about: > > class com.packageName.MyClass > { > public static function create():MyClass > { > var inst:MyClass = new MyClass(); > return inst; > } > > public function toString():String > { > return "[MyClass]"; > } > } > > import com.packageName.MyClass; > trace(MyClass.create()); > > > ----- Original Message ----- > From: "Rich Rodecker" <[EMAIL PROTECTED]> > To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com> > Sent: Thursday, December 29, 2005 11:35 PM > Subject: [Flashcoders] Re: calling a static method on dynamically > namedclass? > > > hmm i tried storing a reference to the class in a variable, like > > var myClass = com.packageName.MyClass > > > > myClass.create() > > > > and i got this message: > > Static members can only be accessed directly through classes > > > there's gotta be a way to pull this off. > > > > > > > On 12/29/05, Rich Rodecker <[EMAIL PROTECTED]> wrote: > > > > I know you can instantiate objects by doing: > > > > var myObj = new _global[className](); > > var className = "TestClass"; > > > > but is it possible to call a static method of a class in a similar way? > > Im trying these two ways, and its not working for me: > > > > _global[iconName].create() > > _global[iconName]().create() > > > > > > if I try and do a trace on the class like trace( _global[iconName]) i > get > > undefined. The icon classes are subclasses of movieclip so that might > > make > > a difference. > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders