4 Replies Latest reply on May 15, 2008 2:14 PM by Tikis_Mikis

    Dynamic Class Instantiation with getDefinitionByName

      Ok so I am trying to follow the following example in instantiating a class dynamically:


      My AS3 code looks like this:

      var myClassName:String = event.templateName;
      try {
      var ClassReference:Class = getDefinitionByName(myClassName) as Class;
      var myInstanceObject:* = new ClassReference();
      } catch( e:Error ) {
      Alert.show("Could not instantiate the class " + myClassName + ". Please ensure that the class name is a valid name and that the Actionscript 3 class or MXML file exists within the project parameters.");

      However I get an error: ReferenceError: Error #1065: Variable OrderEdit is not defined.

      The problem is that my class is located in an altogether different project directory from the the calling main project (I include this project with these classes I am trying to dynamically instantiate in the project source path).

      Every example I have seen so far involves some sort of hard coding. I am builidng a plugin/component that I intend to use in various places in my site and have any general hard code is UNACCEPTABLE. How can I make this process COMPLETELY HARD CODE FREE??

      Thanks a ton!