• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Using classes

Guest
Apr 22, 2015 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

482

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
community guidelines
Explorer ,
Apr 22, 2015 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.

Votes

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
community guidelines
Adobe Employee ,
Apr 22, 2015 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

Votes

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
community guidelines
Guest
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

LATEST

thanks, I will try

Votes

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
community guidelines
Explorer ,
Apr 22, 2015 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.

Votes

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
community guidelines