3 Replies Latest reply: May 21, 2012 9:08 PM by Rothrock RSS

    Why can't two class in different packages have the same name in as2?

    xhdreamlover

      When I do this, I go the compiling error message says something like "the leaf node ... has been decode to ...", then what the package are using for ?

        • 1. Re: Why can't two class in different packages have the same name in as2?
          Ned Murphy MVP

          You should include the actual entire error message, not something like it.  Why would you want to have two classes with the same name in the same file?  I can see how the compiler would have an issue picking which to use in that scenario?

          • 2. Re: Why can't two class in different packages have the same name in as2?
            xhdreamlover Community Member

            Not two classes in the same file, is two classes in different packages.

            For example, I have a folder "test". In "test", I have a "test.fla" file and two subfolder "p1" and "p2".

             

            In p1, I have "CA.as" file which defines a CA class as bellow:

            // Content of "test\p1\CA.as"

            class p1.CA

            {

                public function CA()

                {

               }

            }

             

            In p2, I also have "CA.as" file which also defines a CA class as bellow:

            class p2.CA

            {

                public function CA()

                {

               }

            }

             

            If I try to use both p1.CA and p2.CA in test.fla, I'll get an error when compile. (My Flash CS4 is not an English version, and I'am not sure if I can translate it accurately, so I would not paste it here.)

            In my opition, the pakcage feature (p1 and p2 here) is intended to avoid name conflict. But the situation here realy make confused about this.

            So any explanation will be much appreciated !

            • 3. Re: Why can't two class in different packages have the same name in as2?
              Rothrock Community Member

              I think the problem is that you are trying to use import statements for both of them?

               

              The import statement doesn't actually "import" anything. It just makes a shortcut for refering to the class.

               

              So

               

              import p1.CA;

               

              Allows you later to do this:

               

              var myCA:CA = new CA();

               

              But when you import both p1.CA and p2.CA Flash doesn't know what to resolve the second one to since the "shortcut" for CA is already used.

               

              If you need to do this then you can use the full package name each time:

               

              var myCA1:p1.CA=new p1.CA();

              var myCA2:p2.CA=new p2.CA();

               

              Of course I'm guessing this is just an example? If it really is this simple of a structure why do you need two CA classes?