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 8443629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:11:24+00:00 2026-06-10T09:11:24+00:00

How do I do this? public class SuperClass extends MovieClip { public static var

  • 0

How do I do this?

public class SuperClass extends MovieClip {
  public static var test:String = 'Hello world';
}

public class SubClass extends SuperClass {
  public function SubClass() {
    var unit = new Unit();
    addChild(Unit);
  }
}

public class Unit extends MovieClip {
  public function Unit() {
    //Get variable:test from SuperClass??
    trace(SubClass.test); //Error
  }
}

Hope you understand what I want to do?
Want to get the variable ‘test’ from the SuperClass in my new Unit added in SubClass.

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-10T09:11:26+00:00Added an answer on June 10, 2026 at 9:11 am

    In this case your class named SubClass uses the Unit class through composition, not inheritance. As such the Unit class knows nothing about SubClass or SuperClass or any of their properties like the test property.

    You can, however, pass a value into the Unit class through it’s constructor (or just set a value directly onto a property of the Unit class):

    (showing the last two classes only)

    public class SubClass extends SuperClass {
    
      public function SubClass() {
        var unit = new Unit(test);
        addChild(Unit);
      }
    }
    
    public class Unit extends MovieClip {
    
      private var test:String;
    
      public function Unit(test:String) {
        this.test = test;
      }
    }
    

    [Edit]

    Since your Unit class needs to access many properties of SubClass (and/or SuperClass), you might want to just pass an instance of SubClass to Unit:

    public class SubClass extends SuperClass {
    
      public function SubClass() {
        var unit = new Unit(this);
        addChild(Unit);
      }
    }
    
    public class Unit extends MovieClip {
    
      private var subClass:SubClass;
    
      public function Unit(subClass:SubClass) {
        this.subClass = subClass;
        trace(subClass.text);
      }
    }
    

    How you actually solve this depends on your use case. But there is no fundamental shortcut to do what you are asking.

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

Sidebar

Related Questions

I have a class like this : public class SubClass <T> extends SuperClass<Collection<T>>{ public
I have this demo code: class Test2 extends Test { public int number =
I got a superclass like this: public class SuperClass extends Activity and a child
I have the following code: class SuperClass { public static String getName() { return
I have created this Pool that has 5 static variables. public class FruitPool extends
Superclass: public class CwDB{ protected LinkedList<Entry> dict = null; public CwDB(String filename){ this.dict =
My model class is like this: Public class abc { public string p1 get;
I created a class with properties like this public class Dependencies { public string
I have a base class like this: public class BaseResponse { public string ErrorMessage
I have this simple interface/class: public abstract class Message {} public class Message1 extends

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.