4 Replies Latest reply on Nov 15, 2006 5:51 AM by Newsgroup_User

    Create Variable Types dynamically

    oceanfeeling Level 1
      I wonder if it is possible in Flash to create variables dynamically.

      I am using an xml file that feeds the Flash application. In this file I would like to declare the variables (actually class instances) and their type.

      I have some AS classes, let's say Box.as (class Box).
      So if in my xml file I had something like <var name="mybox" type="Box" />
      in Flash I would like to create a variable named mybox which would be a type of Box.

      I need this because I don't know beforehand the variables that are needed. These will be declared in this xml file.

      The typical declaration is be
      var myname:Box = new Box();

      Can I do the same dynamically?

      i.e.
      function createVar(name, type)
      {
      var name:type = new type(); // compile-error
      }

      createVar("myname", Box);

      Any help would be great.

      Thanks