Search code examples
flashapache-flexflex4stage

How to get a reference to system manager from anywhere?


How do you get a reference to the system manager from any class in your application?

For example say I have:

/** 
 * Value object class
 **/
public class Person {

    public function Person():void {
        var sm:SystemManager = ...; // need reference to sm
        var stage:Stage = sm.stage;
    }

    public var name:String;

} 

Solution

  • You can use FlexGlobals.topLevelApplication for this. It will return a reference to your main Application instance. And from there you can easily get the SystemManager instance, like so:

    var sm:SystemManager = Application(FlexGlobals.topLevelApplication).systemManager