/ Published in: ActionScript 3
URL: http://stackoverflow.com/questions/370222/accessing-the-document-class-in-as3
You can use a singleton for your document class (Main, in your example), which allows you to access the instance from anywhere.
The document class is a pretty good candidate for the singleton pattern, because generally there should only be instance available.
Expand |
Embed | Plain Text
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(); } }
You need to login to post a comment.
