5 Replies Latest reply on Apr 14, 2011 10:01 AM by GordonSmith

    Basic AS3 questions

    leblon1967

      I have severa books on AS3 and none of them explicitly get me off ground zero of what types of projects, packages, and/or class files are needed to just run a simple test. I'm sure it is all explainable, but I haven't seen that yet.

      1. Does a project have to have a package?

      2. What names in the code have to match the filename?

      3. Can I just rename files and move them around as needed?

      4. Are the files just text files? IE can I rename a package to a class file or to an .as file?

      5. I have yet to get even the simplest test running. Usability of this product is very poor.

        • 1. Re: Basic AS3 questions
          Vikash.kumar29 Level 3

          Hi lenlon,

           

          Please see my inline comments on the basic question you have asked:

           

          1. Does a project have to have a package?

          *** No, Its not required to have a package inside a project. Though in Flash builder 4 when you keep any mxml or as file in the src folder it is called default package. However a package is only a logical grouping of classes, which you need to refer in your project.

           

          2. What names in the code have to match the filename?

          *** Every .as file which is having class must be named as that class name, for simple actionscript file you can name anything whicherver suits you.  Howvever for every file you are free to name it as per your requirements.

           

          3. Can I just rename files and move them around as needed?

          ***Whenever you rename/move a actionscript class file, make sure your class name is also renamed and package name is correct to your current package structure relative to the 'src' directory of your project. See above point 2.

           

          4. Are the files just text files? IE can I rename a package to a class file or to an .as file?

          *** you are free to rename any package to any name which is permissable under current OS. Like you cannot create a package with name 'con' on windows os. One point more, when you rename a package make sure every as class have the correct package

           

          5. I have yet to get even the simplest test running. Usability of this product is very poor.

          ***To run a project every Flex project must have a application file which is required to run.

           

          Please do let me know if you require any more help.

           

          Thanks and regards

          Vikash Kumar

          • 2. Re: Basic AS3 questions
            leblon1967 Level 1

            Vikash,

            I wanted to thank you for your kind replies. I'm just trying to get comfortable

            with AS3.

            Based on what you said, I can't have an .as file with more than one class or

            package, correct?

            Thanks again,

            Dave

            • 3. Re: Basic AS3 questions
              eprevot123 Level 2

              You can have an inner class in an as file, like in Java.

              If you create MyClass.as containing a public class named MyClass, and also an inner class named InnerClass, the inner class will be visible only by MyClass, and not by any other classe in the project.

              • 4. Re: Basic AS3 questions
                GordonSmith Level 4

                Actually, AS3 doesn't have inner classes like Java. You can't write

                 

                package

                {

                    class A

                    {

                        class B

                        {

                        }

                        class C

                        {

                        }

                    }

                }

                 

                where classes B and C are inside class A.

                 

                However, you can write a file with the structure

                 

                package

                {

                    public class A

                    {

                    }

                }

                 

                internal class B

                {

                }

                 

                internal class C

                {

                }

                 

                where classes B and C are in the same file but outside the package. They must be given the "internal" access modifier, or no access modifier. They can be used by any code in the same file, but not by any code in other files.

                 

                Gordon Smith

                Adobe Flex SDK Team

                • 5. Re: Basic AS3 questions
                  GordonSmith Level 4

                  BTW, the simplest "Hello World" application in AS3 is

                   

                  HelloWorld.as:

                   

                  package
                  {

                      import flash.display.Sprite;

                      public class HelloWorld extends Sprite

                      {
                          public function HelloWorld()
                          {
                              super();
                              trace("Hello World");
                          }
                      }

                  }

                   

                  The Flash Player requires that the main class of a SWF must be a subclass of Sprite.

                   

                  If you're using Flash Builder, just choose File > New > ActionScript Project to create this kind of application.

                   

                  Gordon Smith

                  Adobe Flex SDK Team