4 Replies Latest reply on Dec 26, 2006 1:14 PM by FlightGuy

    It seems there is a bug in flex

    01robert
      The following script will raise a error: ReferenceError: Error #1065: the variable TestClass has not been defined
      private function test2():void{
      var ClassReference:Class = getDefinitionByName("TestClass") as Class;
      var instance:Object = new ClassReference;
      }

      It works correctly:
      private function test2():void{
      var bb:TestClass=new TestClass(); // added this line;
      var ClassReference:Class = getDefinitionByName("TestClass") as Class;
      var instance:Object = new ClassReference;
      }

      It seems that it always need declare the class explicitly. If so, it will lose the convenience which getDefinitionByName brings.

      Is it a bug or I have misunderstood it ?

      thanks.
        • 1. Re: It seems there is a bug in flex
          Khinu
          I have the same problem i have posted a new Topic without response. Regarding to your code, it works even if you dont intstantiate TestClass:

          var bb:TestClass; // added this line
          ....

          Simply by referencing the class you will use the Class definition or whatever its imported and the error its not throwed.
          • 2. Re: It seems there is a bug in flex
            FlightGuy Level 1
            I use getDefinitionByName in functions in which I have not made static reference to the type, and have not encountered this problem. Other parts of my application, however do, and perhaps that's the difference.

            What is the package of your TestClass? Is it in the default package? If not, do you get this problem when you specify its fully qualified class name? If, in your example (the working one), you query ClassReference.getQualifiedClassName(), what does it say?

            Tim
            • 3. Re: It seems there is a bug in flex
              FlightGuy Level 1
              After some further examination, yes - if I have declared a variable of this type anywhere in my application, I'm free to use getDefinitionByName(), but if I don't declare such a variable I get the same error. This is frustrating, and doesn't appear to get any mention in the docs. This suggests to be it's a bug?
              • 4. Re: It seems there is a bug in flex
                FlightGuy Level 1
                The following is courtesy of Matt on the flexcoders group:

                quote:

                You need to make sure that the class gets linked into your SWF. You don't
                need to instantiate it but you need to declare a variable with the type of
                the class that you want. You can also use the –include-classes directive to
                the compiler to force the class to be available. Check the docs for more
                details.