0

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?

Mattias
  • 3,907
  • 4
  • 28
  • 50

2 Answers2

1

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.

weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
0

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?

Amy Blankenship
  • 6,485
  • 2
  • 22
  • 45