PureMVC Loading PureMVC
In large-scale applications, it is often useful to create independent micro-applications that serve almost as ‘plug-ins’. Suppose a micro-application is developed with PureMVC and is to be loaded into another application itself written in PureMVC. It is useful to think about a well-defined interface for allowing the loading application to provide data to the loaded micro-application and delay the Startup Notification until after loading and data initialization. One thing that’s easy to forget (like I did when copying and pasting code) is to ensure the Loader loads the micro-application into a separate ApplicationDomain (old-school we used to call it function table before these newfangled OOP languages).
PureMVC implements the Facade as a Singleton. If the micro-application is loaded with a context of ApplicationDomain.currentDomain, the loaded Facade will reference the already existing instance present in the loading application (as they both reference the Facade class). Instead, use some thing like,
var urlRequest:URLRequest = new URLRequest(_file);
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = new ApplicationDomain();
Then, the Facade from the loaded Object will not conflict with that from the loading application. Simple point, but easy to forget, especially when copying loading code from another application into a new Proxy. Hope it saves you some time.