Highlighted

Using classes

New Here ,
Apr 22, 2015

Copy link to clipboard

Copied

Good morning, I'm doing a project in flash air using a class.

In the "Properties" I can put a single class.

If I need to use more classes where I add?

TOPICS
Development

Views

332

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Using classes

New Here ,
Apr 22, 2015

Copy link to clipboard

Copied

Good morning, I'm doing a project in flash air using a class.

In the "Properties" I can put a single class.

If I need to use more classes where I add?

TOPICS
Development

Views

333

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 22, 2015 0
Explorer ,
Apr 22, 2015

Copy link to clipboard

Copied

Hi, I don't really know what you mean with "flash air using a class".

You have your main class, where everything starts. Your Main, usually extends from Sprite.

After that, you can add all the classes you need and instantiate them in your main class. They can extend from Sprite, EventDispatcher... etc, or not.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 22, 2015 0
Adobe Employee ,
Apr 22, 2015

Copy link to clipboard

Copied

Hi

Is your question about putting multiple classes in the same "Actionscript" file ?

You can only have one externally visible class in one ".as" file. Though you can have classes outside the package .

Example:

(1) Sample 1 :

package

{

  public class PubClass

  {

       public function PubClass()

       {

            trace("PubClass constructor");

            var b:AnotherClass = new AnotherClass();

       }

  }

  internal class AnotherClass {

       public function AnotherClass() {

            trace("Hello");

       }

  }

}

You will get error similar to :

An externally-visible definition with the name 'AnotherClass' was unexpectedly found.

Though, this will be the legal way to add another class :

(2) Sample 2 :

package {

       public class PubClass {

           public function PubClass() {

                 var b:AnotherClass = new AnotherClass();

            }

       }

}

     class AnotherClass {

            public function AnotherClass() {

                 trace("Hello");

            }

      }

Class 'AnotherClass' is only visible to class PubClass - you cannot have more than one visible class in one file (exactly what the error message states).


Though, you should try to keep only one class in a single file, because it will be easier for you to find your class at any point of time. Also, it will be more handy with any source control system (if a file changes, then you know that a particular class has changed).

Tell me if it was what you were looking for, and if it solves your query.

For more references, check out this and this

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 22, 2015 0
New Here ,
Apr 22, 2015

Copy link to clipboard

Copied

thanks, I will try

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 22, 2015 0
Explorer ,
Apr 22, 2015

Copy link to clipboard

Copied

You put your other classes in the same folder/directory as your Main class.

The Main class is the only one that you have to enter the location for in Properties. AIR needs to know which is the first class it must instantiate to start the application. You enter the name of this class in Properties and by convention, it is called Main.as.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 22, 2015 0