You need to declare variables, you don't have to create instances.
There is also the unofficial [Mixin} ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of keith Sent: Sunday, September 30, 2007 3:13 PM To: [email protected] Subject: Re: [flexcoders] Dynamically convert a String to a Class? Thanks Dave, For this code to work, a ComboBox must have already existed or been declared as a variable somewhere on the stage. Does this mean I have declare instances of all the components I might ever use dynamically ahead of time for this to work? //================================== //So far this is what I got to work after reading the LiveDocs: //Works only if an instance of ComboBox has already been declared. //Does not work just by importing mx.controls.ComboBox alone. //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////// var ClassReference:Class = flash.utils.getDefinitionByName("mx.controls.ComboBox") as Class; var instance:Object = new ClassReference(); addChild(DisplayObject(instance)); //=================================== I'm open to more inside details or helpful gotchas on this. -- Keith H -- Dave Carabetta wrote: > > Check out the LiveDocs for getDefinitionByName(): > > http://livedocs.adobe.com/flex/201/langref/flash/utils/package.html <http://livedocs.adobe.com/flex/201/langref/flash/utils/package.html> > <http://livedocs.adobe.com/flex/201/langref/flash/utils/package.html <http://livedocs.adobe.com/flex/201/langref/flash/utils/package.html> > > > Regards, > Dave. > Cynergy Systems > > On 9/30/07, *keith* <[EMAIL PROTECTED] <mailto:khair%40nc.rr.com> <mailto:[EMAIL PROTECTED] <mailto:khair%40nc.rr.com> >> wrote: > > I want to convert something like the String "mx.controls.ComboBox" > to a > Class. > I would use this to declare components or other classes at runtime. > *Please don't laugh at me* > > //============================== > //In areas where I CAN do this... > //--------------------------------------------- > var testA:* = new mx.controls.ComboBox(); > addChild(testA); > //============================== > > //===================================== > //I want to DYNAMICALLY do the same... > //-------------------------------------------------------- > var classname:Class = Class("mx.controls.ComboBox"); > var testB:* = new classname(); > addChild(testB); > //===================================== > > //But get a this type of error---> TypeError: Error #1034: Type > Coercion > failed: cannot convert "mx.controls.ComboBox" to Class. > > -- Keith H -- > > >

