Question

I have a Singleton class instantiated in Main.swf located at domainA. The file loads Game.swf from domainB via LoaderMax (http://www.greensock.com/). When I try to access the Singleton I guess this is not the same as the on instatiated in Main.swf.

Is there any way of forcing this?

Was it helpful?

Solution

It should be the same singleton if your files are loaded into the same application domain. You can use LoaderContext to do that.

Also, you can use a dependency injection framework, like SwiftSuspenders, to take care of this more elegantly, but since most of these rely heavily on describeType, I would advise to test for performance issues if you need to inject stuff into a lot of game objects.

OTHER TIPS

This is one of the many problems with using Singleton (http://misko.hevery.com/2008/11/21/clean-code-talks-global-state-and-singletons/). Might I suggest that, instead, you simply pass the instance into the game.swf, and leave the responsibility of how that is instantiated to main.swf?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top