How can instantiated classes access the Document class?
Even after I name the Document class using the Properties bar in Flash, att
You can use a singleton for your document class (Main
, in your example), which allows you to access the instance from anywhere.
public class Main extends Sprite {
private static var _instance:Main;
public static function get instance():Main { return _instance; }
public function Main() {
_instance = this;
// etc...
}
// etc...
}
Then you access the Main
instance like this:
public class Other {
public function Other() {
Main.instance.usefulInstanceMethod();
}
}
The document class is a pretty good candidate for the singleton pattern, because generally there should only be instance available.