Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:04:08+00:00 2026-06-08T08:04:08+00:00

I need a little help understanding how classes work in Actionscript 3. I understand

  • 0

I need a little help understanding how classes work in Actionscript 3. I understand you start with “package” and why and then go to import any necessary libraries, as well as then naming the class and stating if it’s public/private and extends anything.

After that is what I don’t understand. It seems you write “(public) function class name()

I don’t understand why you do this and what goes in the curly brackets.

I’ve probably missed a bit of earlier reading because I’ve done a little reading but I can’t seem to get it.

Could someone try explain it to me? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:04:09+00:00Added an answer on June 8, 2026 at 8:04 am

    ActionScript 3 Classes

    The package statement.

    Okay, so firstly like you mentioned, a class must be wrapped by a package1. This gives us the first block, where you need to define the class.

    package
    {
        // Your class here.
    }
    

    The package statement reflects the location of the class relative to the .fla2. For example, if you have a folder “classes” within the same directory as the project .fla, then classes within that folder will need a package statement that reflects that:

    package classes
    {
        // Your class here.
    }
    

    Defining the class.

    Within a package statement, you may insert one class. Do not confuse this with the package itself, which can contain many classes – each class just needs to have its own file with the same package statement.

    A class definition is made up of up to 5 parts:

    1. The namespace. A class can be internal or public. An internal class can only be seen by classes within the same package, whereas public classes can be seen from anywhere in the project.
    2. The class name.
    3. A base class (optional). If a base class is defined, then your new class will act as an extension to that class, inheriting all of the qualities of the base class.
    4. An interface to implement (optional). Interfaces are an advanced topic thus I suggest you forget about these for now until your AS3 and OOP have evolved.

    If you wanted to create a class called “Person” within the package classes, then we would end up with:

    package classes
    {
        public class Person
        {
            // Class qualities here.
        }
    }
    

    Properties.

    Classes can contain properties. Properties are defined using the var keyword. They may belong to one of a number of namespaces (including your own) and are used to hold values that belong to your class. Properties are most commonly found clustered together at the top of your class.

    Our Person class may enjoy the properties height and weight:

    package classes
    {
        public class Person
        {
            // Properties.
            public var height:Number = 1.70;
            public var weight:Number = 67.5;
        }
    }
    

    These properties can be accessed via any instance of Person that you create. Each instance will have its own set of these properties.

    Class constructors (I believe this is what you’re asking about).

    Constructors are used to hold logic that should be run as soon as an instance of your class is created. The class constructor has the same name as the class itself. It must be public and it does not return anything. Constructors can accept arguments, which are typically used to pass in references to dependencies for that class or required values.

    package classes
    {
        public class Person
        {
            // Properties.
            public var height:Number = 1.70;
            public var weight:Number = 67.5;
    
            // Constructor.
            public function Person(height:Number, weight:Number)
            {
                this.height = height;
                this.weight = weight;
            }
        }
    }
    

    Methods.

    Methods are used to hold logic that can be run when calling that method. Methods often return values and can accept arguments. Methods can belong to any namespace that you would expect properties to be able to belong to.

    We may want to be able to easily determine the BMI of each instance of Person that we create, so we should create a method for that:

    package classes
    {
        public class Person
        {
            // Properties.
            public var height:Number = 170;
            public var weight:Number = 65.5;
    
            // Constructor.
            public function Person(height:Number, weight:Number)
            {
                this.height = height;
                this.weight = weight;
            }
    
            // Determine my BMI and return the result.
            public function getBMI():Number
            {
                return weight / (height * height);
            }
        }
    }
    

    Instances.

    Now that we’ve defined our new class, we can create instances of this class using the new keyword. This can be done from anywhere that can access the Person class, which in this case is anywhere in the project because we’ve made the class public.

    Though the class is public, accessing it from anywhere outside of the package it belongs in will require the use of an import statement. This statement will need to be used within any class that belongs to a different package. The import statement follows the same name used for the package and includes the name of the class you want to include on the end:

    import classes.Person;
    

    Once you’ve imported Person, you can create instances of it and assign them to a variable with different height and weight values:

    var marty:Person = new Person(71, 1.76);
    var bruce:Person = new Person(96.4, 1.72);
    

    We can then obtain the BMI for each person using their getBMI() method:

    trace(marty.getBMI()); // 22.9
    trace(bruce.getBMI()); // 32.6
    

    1 You can place classes outside of a package which can be referred to in the same .as file.
    2 You can add more source paths, and packages can be relative to that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little help understanding how HTML forms work. It is my understanding
I'm a SQL noob, and I need a little bit of help understanding the
I need a little help with understanding what can I do and cannot in
I'm new to android and I'm need a little help understanding how to move
I need a little help understanding something. I am using the colorbox plugin to
Hi need a little help understanding the following statement and the logic of what
Hi I need a little help with understanding how to send image uri via
I'm new in SQL and need little help to understand parts in this SQL
I think I need a little help understanding how a simple Rails 3.2 one-to-one
So I need a little help with understanding the best way of getting input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.