6 Replies Latest reply on Jul 12, 2009 2:50 AM by DaveFastFingers

    How to create objects dynamically (with dynamic # of parameters)

    DaveFastFingers Level 1

      I need to create a set of objects based on a definition from an XML file (obtained from the server) and add them to my scene.

       

      I understand how to create the object using getDefinitionByName (and the limitations regarding classes needing to be referenced to be loaded into the SWF).

       

      But some objects require parameters for the constructor, and some don't. The XML can easily pass in the required parameter information, but I can't figure out how to create a new object with a dynamic set of arguments (something akin to using the Function.call(obj, argsArray) method.


      For example, I need something like this to work:

      var mc=new (getDefinitionByName(str) as Class).call(thisNewThing, argsArray)

       

      Currently this is as far as I can get:

      var mc=new (getDefinitionByName(str) as Class)(static, list, of, arguments)

       

      Thoughts?