7 Replies Latest reply on Nov 3, 2008 4:40 PM by Newsgroup_User

    getDefinitionByName Problem

    Khinu
      Im trying to use getDefinitionByName and its returning the error: ReferenceError: Error #1065: Variable XClass is not defined...

      var protoClass:Object = getDefinitionByName("path.to.XClass");

      Surfing through the net i have found that the VM or Flash or whatever, have no definition of the class until the class its "used" in something else. For example, this avoid the error:

      var protoClass:Object = getDefinitionByName("path.to.XClass");
      var dummy:XClass;

      This is a really headache since i have to include every class that could be used. This make pieces the advantage of dynamic instantiation. Theres any other way to avoid refering to the specific class and still beign able to dynamically instantiate classes in Flex 2?

      Help !!!!

        • 1. getDefinitionByName Problem
          oconq Level 1
          I've exactly the same problem; please !!
          • 2. Re: getDefinitionByName Problem
            FlightGuy Level 1
            See my recent post on this forum entitled "It seems there is a bug in flex".
            • 3. Re: getDefinitionByName Problem
              Khinu Level 1
              Poor programmed
              • 4. Re: getDefinitionByName Problem
                mike_morearty Level 1
                This is by design. There really is no other way it could have been done, because you don't want to link the *entire* Flex SDK into every single Flex application -- you only want to link in those parts of Flex that are actually used by that particular app. If getDefinitionByName() were going to just magically work for all classes, then that means all classes were in the SWF -- which means your SWFs would get enormous.
                • 5. Re: getDefinitionByName Problem
                  Edgar Díaz
                  Ok Mike, I understand your reasons, but I'm trying to use this "function" to create a "class" in runtime, more exactly to create a "Class Factory" with this "dynamic class" and use it to set an "itemrenderer" in a "DataGridColumn". And for "getDefinitionByName" function works, i need to instantiate a variable with this class and import its namespace, but this is not functional for my aims. Can you help with another way to use this function or another to fulfil my aims?

                  Thanks
                  • 6. Re: getDefinitionByName Problem
                    Level 7

                    "Edgar D?az" <webforumsuser@macromedia.com> wrote in message
                    news:geo537$qv1$1@forums.macromedia.com...
                    > Ok Mike, I understand your reasons, but I'm trying to use this "function"
                    > to
                    > create a "class" in runtime, more exactly to create a "Class Factory" with
                    > this
                    > "dynamic class" and use it to set an "itemrenderer" in a "DataGridColumn".
                    > And
                    > for "getDefinitionByName" function works, i need to instantiate a variable
                    > with
                    > this class and import its namespace, but this is not functional for my
                    > aims.
                    > Can you help with another way to use this function or another to fulfil my
                    > aims?

                    Have you checked out
                    http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
                    Q13


                    • 7. Re: getDefinitionByName Problem
                      mike_morearty Level 1
                      Edgar: Hmm, I don't quite follow what you're trying to do. Can you post some sample code?

                      Your message implies that you are hoping to use getDefinitionByName() to return some sort of handle to a NEW class that doesn't yet exist -- e.g.:

                      var c:Class = getDefinitionByName("BrandNewClass") as Class;
                      var instance = new c();

                      ... but you can't do that. getDefinitionByName() is used to return handles to classes that already exist.

                      If it helps at all, ActionScript is compliant with the ECMAScript language, which basically means that ActionScript can do all the same tricks that JavaScript can do (except for eval(), which not part of the ECMAScript spec and is not supported by the Flash player). This means that if you want to do JavaScript-style dynamic prototype-based programming, you can.