> I thought that by importing the components package, this made sure > all the component classes were included in the SWF. Apparently not. That's correct... simply importing a class does not cause it to be linked into the SWF. > So, the challenge is how to pull in (instantiate) > a query-driven selection of component classes at runtime. What's the challenge to solve? You ensure that the components you might want are linked into the SWF, and then you instantiate them with the 'new' operator. - Gordon
________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of phall121 Sent: Thursday, June 07, 2007 9:58 AM To: [email protected] Subject: [flexcoders] Re: Converting a string to a Class Thanks Gordon, this worked! I tried your original getDefinitionByName() solution...it worked on one app, but failed on another, with: ReferenceError: Error #1065: Variable TestComp1 is not defined. I eventually figured out that the component was not in the SWF. I thought that by importing the components package, this made sure all the component classes were included in the SWF. Apparently not. But, declaring them with private static var works. However, in building a Dynamic UI we have an expanding list of components...a selection of which are instantiated at runtime for an individual user. So, the challenge is how to pull in (instantiate) a query-driven selection of component classes at runtime. I invite you to the thread "Selecting which Child Components to add at runtime", where this inquiry continues. --- In [email protected] <mailto:flexcoders%40yahoogroups.com> , "Gordon Smith" <[EMAIL PROTECTED]> wrote: > > I think the convention is to declare a static var in your Application > script: > > private static var buttonDependency:Button; > > - Gordon > > ________________________________ > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of Troy Gilbert > Sent: Wednesday, June 06, 2007 4:39 PM > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Subject: Re: [flexcoders] Converting a string to a Class > > > > What's the best way to ensure that a class gets linked into the SWF? > Obviously a reference to the class from outside of the class will do it, > but is there any pattern for forcing a class to be linked in? > > Troy. > > > > On 6/6/07, Gordon Smith <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > > wrote: > > > > The getDefinitionByName() function in the flash.utils package > can convert a String specifying a fully-qualified classname to a Class, > as long as the class is actually in the SWF or the Player. For example, > > var c:Class = > Class(getDefinitionByName("mx.controls.Button")); > > is the same as > > var c:Class = Button; > > - Gordon > > ________________________________ > > From: [email protected] <mailto:flexcoders%40yahoogroups.com> > [mailto:[email protected] <mailto:flexcoders%40yahoogroups.com> <http://yahoogroups.com <http://yahoogroups.com> > ] On Behalf > Of phall121 > Sent: Wednesday, June 06, 2007 9:06 AM > To: [email protected] <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Converting a string to a Class > > > > > Embarrassingly basic: > > How, in AS, can you convert a string ("components.Comp1") into > the > actual reference to the component? > > I have a function that requires a parameter of type Class. > > private function fAddCustomView(compClass:Class):void > > From an array I have a listing of package/components (as > string): > > "components.Comp1" > "components.Comp2" > "components.Comp3" > > How can I convert these strings to actual references to the > components themselves...so I can send any selection into the > function as a Class? > > I tried: > private function fAddComp():void > { > var clComp:Class = Class(acCompList.getItemAt(2).compname); > fAddCustomView(clComp); > } > > private function fAddCustomView(compClass:Class):void > > This didn't work. Error said: > > "Type Coercion failed: cannot convert "components.Comp1" to > Class." > > Seems a basic question...How do you do it? Thanks. >

