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!
In this case your class named
SubClassuses theUnitclass through composition, not inheritance. As such theUnitclass knows nothing aboutSubClassorSuperClassor any of their properties like thetestproperty.You can, however, pass a value into the
Unitclass through it’s constructor (or just set a value directly onto a property of theUnitclass):(showing the last two classes only)
[Edit]
Since your
Unitclass needs to access many properties ofSubClass(and/orSuperClass), you might want to just pass an instance ofSubClasstoUnit:How you actually solve this depends on your use case. But there is no fundamental shortcut to do what you are asking.