tags:

views:

606

answers:

1

I have a flash application (pure AS, no Flex framework) that I'd like to embed inside of a flex application using SWFLoader.

Embedding one instance works well. However, when I try to embed multiple instances (each with a separate SwfLoader), there is really strange behavior that seems to be caused by clashes among the class definitions of the multiple instances. This flash application is written with a lot of singleton classes, so my guess is that these singletons are overriding each other and causing the weird behavior.

I tried loading the flash application into a child applicationdomain, but that doesn't seem to help much either. Has anyone faced this problem?

+2  A: 

You would want to load the SWF into it's own application domain (Not a child) to avoid name clashing.

There are three types of application domains:

var swfLoader:Loader = new Loader();
var loaderContext:LoaderContext = new LoaderContext();

// child SWF adds its unique definitions to
// parent SWF; both SWFs share the same domain
// child SWFs definitions do not overwrite parents
loaderContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);

// child SWF uses parent domain definitions
// if defined there, otherwise its own
loaderContext.applicationDomain = ApplicationDomain.currentDomain;

// child SWF domain is completely separate and
// each SWF uses its own definitions
loaderContext.applicationDomain = new ApplicationDomain();

// Load the swf file
swfLoader.load(new URLRequest("file.swf"), loaderContext);

I would suggest using the first method, as it will not overwrite definitions.

LiraNuna