Share a as3 class between domains

169 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

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?