Jump to content
Search Community

Application Domain issue SOLVED

darloScott test
Moderator Tag

Recommended Posts

Hi,

 

I had a quick look around and couldn't find anyone having the same problem but sorry if this has been covered already...

 

Scenario

I'm loading a swf file into a new application domain which contains MovieClips which style the application, when the user selects a new theme I want to unload this swf and load a new swf into a new application domain which contains new theme MovieClips to change the appearance of the application.

 

Problem

1. So i create a new application domain:

_newDomain =  new ApplicationDomain();	
_appContext = new LoaderContext(false, _newDomain);

 

2. I then load the swf into it:

_loader = new SWFLoader("Squares.swf", {onComplete:completeHandler,context:_appContext});
_loader.load();

 

3. I then add an item from the loaded swf to the stage:

var ClassReference:Class = _newDomain.getDefinition("Square") as Class;
_square = new ClassReference();				
addChild(_square);

 

4. When the user wants to swap a theme I unload the first loaded swf:

removeChild(_square);
_square = null;	
_loader.unload();
_loader.dispose();

 

5. Here is where the problem lies: I test that the swf has been unloaded successfully by trying to add another instance of the square from the swf that should no longer exsist, I didn't expect the ClassReference to be able to access the square but it does....another instance of the Square is added. So the question is how do I get rid of the swf file succesfully? I don't have any listeners, timers etc setup in the main movie which would restrict the swf being eligible for garbage collection so I'm lost as to what is going on.

var ClassReference:Class = _newDomain.getDefinition("Square") as Class;
_newSquare = new ClassReference();	
addChild(_newSquare);

 

I have added a little example as an attachment, you may need to point the fla to the greensock swc using file>actionscript settings>library path:

 

Any help would be appreciated!

 

Thanks,

 

Scott

Link to comment
Share on other sites

The problem looks like you were keeping a reference to the ApplicationDomain (as _newDomain) in your Main class which prevented it from being garbage collected. Just because you unload a swf doesn't force all of its classes/definitions to be scrubbed from the ApplicationDomain.

 

If you set _newDomain to null after you unload, you should be all good.

 

Also, you don't need to split the unload() and dispose() into different calls - you can just dispose(true) which will unload as well.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...