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
  • Can you try with two different applications? That way we can be sure if your singleton's are to be blamed or not? Commented Mar 5, 2009 at 20:32
  • When the two applications are loaded in child application domains, the singletons don't clash. It's only when they're loaded into the same application domain that they clash. Let me investigate further to find the bug. Commented Mar 5, 2009 at 20:52

1 Answer 1

2

You would want to load the SWF into its 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.