1 Reply Latest reply on Aug 28, 2006 4:26 PM by Ray Greenwell

    Invisible class mysteries

    Duster_IDF
      Consider this class:


      // -- file test/Enum.as --

      package test
      {
      // public static const One:Enum = new Enum(new Cloak(), 1); // (1)
      // public const One:Enum = new Enum(new Cloak(), 1); // (2)

      public class Enum {
      public function Enum(cloak:Cloak, i:int) {
      new Cloak();
      trace("Enum", i);
      }
      }
      }

      class Cloak {}
      // -- EOF --


      Then this works like a charm:
      public function testHidden():void {
      new Enum(null, 1);
      new Enum(null, 2);
      }


      Mystery #1: Removing the comment for (1) compiles but causes this Runtime error:
      TypeError: Error #1115: Enum.as$45::Cloak is not a constructor.
      at test::Enum$cinit()

      Mystery #2: Removing the comment for (2) compiles but causes this Runtime error:
      Error: Error #1023: Stack overflow occurred.
      at Enum.as$45::Cloak$iinit()[test\Enum.as:16]
      at test::Enum$iinit()[test\Enum.as:7]
      ...
      at test::Enum$iinit()[test\Enum.as:7]

      Any ideas?
      --
      Jürgen Failenschmid
        • 1. Re: Invisible class mysteries
          Ray Greenwell Level 1
          I know why #2 is broken: The enum named "One" is not a static, so each time you are constructing an Enum object
          it tries to construct an Enum object in the initializer. That's obviously pretty broken.

          As for #1, I am guessing that the Cloak class will not be known until the Enum class completely initializes, which happens after the assignment of the static variables.