5 Replies Latest reply on May 21, 2007 7:56 AM by kglad

    Question on classes and packages

    hciguy Level 1
      I was reading the Flash CS3 Actionscript 3.0 guide and it says how each external file can only have one class available to internal code. Why? I don't get why you can only have one class available. It says: "only one class in each file can be declared inside a package declaration." Why?

      Also is this only for external .as files?

      Thanks in advance for the help.
        • 1. Re: Question on classes and packages
          hciguy Level 1
          Wait...but then it says you can import more than one class....I am confused. If you can only make one class from a package in an external .as file available then how could you do import.samples.* to make all the classes available?

          I know I am missing something here....

          Thanks.
          • 2. Re: Question on classes and packages
            hciguy Level 1
            Here is what I am referring to: "Actionscript 3.0 allows you to include multiple classes in one source file, but only one class in each file can be made available to code that is external to that file."

            Maybe some kind soul can explain to me?

            Thanks in advance!
            • 3. Re: Question on classes and packages
              kglad Adobe Community Professional & MVP
              you can only CREATE or define one (new) class per as file. the (new) class must have the same name as the file name. because the file can only have one name you can only have one class defined.

              code external to your class file will only use the new class. ie, you won't be able to use external code to create instances of the other classes used in your class file because they aren't created in that class file so their constructors, methods, properties etc are not in that class file. they are in their own class file.

              but you can use any number of classes within your class file that contains a new class. and you can create instances of those other classes IN your class file.
              • 4. Re: Question on classes and packages
                hciguy Level 1
                Okay. So only one public class per .as file....then you have to make one external .as file per class you want to be public? I guess that isn't too bad...so all my class properties I want to be able to access outside of that external file need to be in that class...?

                I'm not use to package-class-property programming structure but am getting used to it.

                Thanks!
                • 5. Re: Question on classes and packages
                  kglad Adobe Community Professional & MVP
                  no external .as file is needed.

                  and only one public class per file. but all the classes methods and properties can be public, if you choose. and you can have many classes defined in one class file.