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?

有帮助吗?

解决方案

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.

其他提示

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?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top