0 Replies Latest reply on Jun 15, 2007 7:25 AM by robbie wu

    a problem about reflect

    robbie wu
      i want to create a new instance with a class name like the java reflect, then call the instance function and get properties.
      i found the flash.utils.getDefinitionByName can new a instance with a class name. then i write the code below:

      package {
      import flash.display.Sprite;
      import flash.utils.getDefinitionByName;
      import com.reflect.Shape;

      public class Reflect extends Sprite
      {
      public function Reflect()
      {
      var ClassReference:Class = getDefinitionByName("com.reflect.Shape") as Class;
      var shape:Shape = new ClassReference();
      trace(shape.getWidth());
      trace(shape.getHeight());
      }
      }
      }

      the code run no problem. but i found a question, in the code, i write like this:
      var shape:Shape = new ClassReference();
      i still bind the shape with the Shape class, i don't get the entire reflect.

      when i change "var shape:Shape" to "var shape:Object", then get the error below:
      ReferenceError: Error #1065: variable Shape not defined。
      at global/flash.utils::getDefinitionByName()
      at Reflect$iinit()[C:\Adobe\Flex Builder 2\workspace\Reflect\src\Reflect.as:10] Text

      who can tell me why?
      thks pre.