Take a look at ApplicationDomain Class it provides some methods that will help
you do this. Here is an example of what you are trying to do I think...
try
{
var myClass:Class =
ApplicationDomain.currentDomain.getDefinition(e.panelClassName) as Class;
var myInstance:* = new myClass();
}
catch(error:Error)
{
Alert.show("Error " + error);
return;
}
First we try to get a class definition from the panelClassName string. I say
try because on thing to keep in mind is that if the Class is not being used
else where in your app it may not be compiled into your swf. In this case the
getDefinition method will throw an error.
If we did get a Class back we then use it to make a real instance of that class.
--- In [email protected], "Ivan" <ivan.ilija...@...> wrote:
>
> I have a menu with XML dataprovider in which each node contains value
> panelClass
>
> <node label="MyPanel" panelClass="com.test.panelTest"/>
>
> panelClass contains a full class name of my panel components which I want to
> display on node double click event.
>
> The problem is how to create class instance from string definition name.
>
> I used something like this:
>
> registerClassAlias( e.panelClassName, Class);
> var ClassReference:Class = getQualifiedClassName(e.panelClassName) as Class;
> var instance:Panel = new ClassReference();
> ....
>
> e is event dispatched from MenuPanel component and it contains member value
> panelClassName with component class name.
>
> By using this code I need to have already created object with panelClassName
> name. That doesn't help me because I have around 40 panel components and it
> would be very annoying to have 40 object just waiting to be initialized.
>
> Anyone has some suggestions?
>
> Cheers,
> Ivan
>
> P.S. Pardon me, this is my first post on the group and I would like to say -
> Hi everyone :)
>