1 Reply Latest reply on Apr 18, 2007 2:17 AM by Ed_Syrett

    Polymorphism

    Tistklehoff
      Hello all.
      I'm a new programmer in this technologies. In my project, I need to create some diferent objects, configured by the user in an xml file. All these objects extends from Canvas and all are defined in separated mxml files.

      I am creating obect instances in runtime with flash.utils.getDefinitionByName, but doesn't work. I've read some articles and this feature works only in built-in classes. In user-defined classes, it works whenever you define one var of your desired type previously. I cannot do that.
      My question is: Does exist another way to make this type of polymorphism?

      Thankyou very much in advance.
        • 1. Re: Polymorphism
          Ed_Syrett Level 1
          getDefinitionByName() will only work if you already reference the class somewhere else in your project. This is because the AS compiler only compiles classes that are actually used. You can have a whole load of files in your Flex project but the compiler won't touch them unless they are actually referenced. So getDefinitionByName isn't much use when you don't know in advance what classes you will load.

          However, in Flex 2.0.1 Adobe introduced Modules. mx:ModuleLoader is a container that takes a url property as a string. You could therefore read the names of the modules from your XML file and then load them into a host container. You could then build each component into a module and load it dynamically at runtime.

          More stuff on Modules here