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

  • Home
  • SEARCH
  • 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 8345899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:50:01+00:00 2026-06-09T06:50:01+00:00

I am creating two classes which define the general structure of objects, and many

  • 0

I am creating two classes which define the general structure of objects, and many subclasses which are variations of the parents. The variables have the type declaration in the superclasses, and the value declaration in the subclasses. However:

[Body_Part_Armor.as]

package  {
    import flash.display.*;
    public class Body_Part_Armor extends MovieClip
    {
        var agility_malus;
        var hp_total;
        var defense;
        var armor_extra_height;
        var armor_extra_width;  
        var hp_left;
        public function Body_Part_Armor()
        {
            hp_left = hp_total;
        }
    }
}

[Chest_Armor_1.as]

package
{
    public class Chest_Armor_1 extends Body_Part_Armor
    {
        agility_malus = 2;
        hp_total = 20;
        defense = 7;
        armor_extra_height = 10;
        armor_extra_width = 6;

        public function Chest_Armor_1()
        {
        }
    }   
}

For the compiler-debug-test Body_Part_Armor and Chest_Armor_1 are completely fine, while

[Weapon.as]

package
{
    import flash.display.*;
    public class Weapon extends MovieClip {
        var weapon_type:Number;
        var n_attacks:Number;
        var damage:Number;
        var precision:Number;
        // some other variables in here
        var is_empty_weapon:Boolean;
        public function Weapon()
        {   
        }           
    }
}

[Empty_Arm_Weapon.as]

package
{
    public class Empty_Arm_Weapon extends Weapon
    {
        is_empty_weapon = true;
        public function Empty_Arm_Weapon() {
        }
    }   
}

give me the following error:
1120: access of undefined property is_empty_weapon
(yet if I write var is_empty_weapon = true; in Empty_Arm_Weapon it will complain about conflict with inherited definition of the variable in the namespace public).

If I define the variable value is_empty_weapon = true in the constructor Empty_Arm_Weapon(), however, i won’t get any error.

I guess I’m missing something really obvious, but I can’t tell the difference between the two cases, yet one works and the other doesn’t.
Can you help 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-09T06:50:02+00:00Added an answer on June 9, 2026 at 6:50 am

    you should move the assignment of the variable into the constructor like:

    package
    {
        public class Empty_Arm_Weapon extends Weapon
        {
            public function Empty_Arm_Weapon()
            {
                is_empty_weapon = true;
            }
        }   
    }
    

    Alternatively you could declare it with a default value of true if you want this for all inheriting classes

    package
    {
        import flash.display.*;
        public class Weapon extends MovieClip {
            protected var weapon_type:Number;
            protected var n_attacks:Number;
            protected var damage:Number;
            protected var precision:Number;
            // some other variables in here
            protected var is_empty_weapon:Boolean=true;
            public function Weapon()
            {   
            }           
        }
    }
    

    Also be sure to scope your variables so they can be accessed by sub-classes if that’s what you want, mark them protected (accessible by this and sub-classes) or public (accessible to this, sub-classes and instances using this object).

    EDIT

    I believe your specific issue you see in the discrepancy between the behavior may have to do with the fact that you have a typed variable in the second case and in the first case the types are not declared. This means they would default to undefined instead of false or null or 0 which may create some strange behavior, either way this isn’t from all I’ve learned the right way to go, setup defaults at definition or in sub-classes override defaults in the constructor.

    http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9d.html

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

Sidebar

Related Questions

I'm creating an iPad app, and I have two classes: NWRootViewController : UITableViewController and
I'm creating a web service with a variety of classes, many of which can
i have two classes which have some common methods like funcA(), funcB() and some
Consider I am creating objects of two classes: BaseClass B; DerievedClass D; and then
Essentially, I am just creating two classes where one class, in this case class
I am creating a registration form which contains two submit buttons. I need to
I'm creating a WP theme that will have two sections midway down the page.
I have two classes Teacher and Student . I am trying to get teacher
I have two questions about creating thread safe types in python, and one related
I use JPA and Hibernate for my project. I have two classes with same

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.