Q:

Actionscript 3.0 - Get variable from superclass to new object

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!

A:

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.

