Hi Amol,
Try creating an instance of the class before you load your XML,
something like:

var aux : MyClass;

and then you do:

 try {
 var dynamicClass: String = "com.apps.MyClass";
 var classRef:Class = flash.utils. getDefinitionByN ame(dynamicClass 
 as Class;
 var myClass:* = new classRef();
 } 
 catch(e:ReferenceEr ror) {
 tracer.traceMe( e.errorID + " "+e.message);
 }

What I did was created a class with all my classes that could be
instanciated dynamically, something like:

public class classes{
   var aux : MyClass;
   ...
}

and then created a variable of this class whenever a needed to
instance dynamically any of this classes

var Classes : classes; 
 try {
 var dynamicClass: String = "com.apps.MyClass";
 var classRef:Class = flash.utils. getDefinitionByN ame(dynamicClass 
 as Class;
 var myClass:* = new classRef();
 } 
 catch(e:ReferenceEr ror) {
 tracer.traceMe( e.errorID + " "+e.message);
 }

Hope this helps!


--- In [email protected], "genius_gen2k" <[EMAIL PROTECTED]>
wrote:
>
> Hello Everyone,
> 
> I am trying to instantiate a class dynamically via the data from an
> external XML file. I get the class name as a String in Flex code and
> then I have applied the below code to instantiate that string as a
> class. Here "MyClass" is a custom class inside the "com.apps" 
> package. I have also imported the above class with fully qualified 
> name.
> 
> I have a code written as below:
> 
> try {
> var dynamicClass: String = "com.apps.MyClass";
> var classRef:Class = flash.utils. getDefinitionByN ame(dynamicClass )
> as Class;
> var myClass:* = new classRef();
> } 
> catch(e:ReferenceEr ror) {
> tracer.traceMe( e.errorID + " "+e.message);
> }
> 
> This code works perfectly with the standard Flex classes like
> "flash.display. MovieClip" but gives me Reference error (code 1065)
> when I use "com.apps.MyClass" for the dynamicClass statement above.
> 
> Anything specific needed to be done with the custom class, to make it
> accessible, the way MovieClip class is accessed. Any ideas of how do 
> i go about this?
> 
> Amol.
>


Reply via email to