Copy link to clipboard
Copied
I am developing desktop application using flash builder 4.7, where I am loading external swf from main swf, but after removing it, it stays in processes, (checking in task manager. os: windows 7), process decreases a little bit, but not as much as it should be. so every time I load it again and remove, process increases and after multiple load, application crushes down. I am removing it like this
if (_loader.numChildren>0)
_loader.removeChildren(0,_loader.numChildren-1);
_loader.unload();
_loader.stopAllMovieClips();
_loader.unloadAndStop(true);
_loader.loaderInfo.removeEventListener(Event.COMPLETE, onComplete);
this.removeChild(_loader);
_loader = null;
I added custom destroy method inside external swf and started calling it. I was removing nearly everything, (nearly saying because it could be something that I've missed, because it's huge project) but still the process remaind same.
Than I created empty swf (new project with no code and nothing in it) and tried to embed it and see what happens. It was all the same...
Then I thought new Air SDK could have fixed this problem, so I updated SDK to 19.0.0.207 currently latest, but still nothing, even though now the process increases higher.
I think it's Flash's gc issue. One of the solution is that to have one and only instance of external swf and removeChild and addChild it everytime you need it. It is kind of bad way to do so. Processes wont increase all the time, but in my case I have many swfs to load and it will slow down my application and for low RAM resource computers it may crush, and It's bad to have unnecessary thing running in background process
so any suggestions are welcome
No need to stop the movie clips and to remove them.. use unloadAndStop() and it'll stop everything and unload the file.. as it's not possible to call the loader contents (the movieClips) to stop after unload method, it's already removed.. So try to use that 3 lines only to unload the file.
Copy link to clipboard
Copied
Try:
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
_loader
= null;
Copy link to clipboard
Copied
I've already had _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); added. after load is complete onComplete is called, I addChild those loaded stuff.
when I try to remove tham I call all those code written in my question. In any case, if I didn't addEventListener Event.COMPLETE, it would throw an erron on removeEventListener Event.COMPLETE, so thats not a case
Copy link to clipboard
Copied
You are using loaderInfo
This code working well here:
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE , onComplete);
function onComplete(e:Event):void {
MovieClip(_loader.content).getChildAt(0).y = 100;
MovieClip(_loader.content).removeChild(MovieClip(_loader.content).getChildAt(1));
addChild(_loader);
}
stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
_loader.unload();
removeChild(_loader);
}
_loader.load(new URLRequest("data/external.swf"));
Copy link to clipboard
Copied
I have similar code to yours, but I only showed you the code which I am using when removing swf. how chan you remove something if it isnot added? It is logical that I had all the addChild and addEventListener codes, but I didn't showed them, they vere unnecessary
Copy link to clipboard
Copied
your code is not similar:
_loader.loaderInfo.addEventListener(Event.COMPLETE , onComplete);
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE , onComplete);
Copy link to clipboard
Copied
You've misundersood my question. I mistyped loaderInfo, but case in different. the loader is in the swf which loads several external swfs. removing those swfs doesn't decrease memory, evet if removed swf is empty (by empty I mean empty project builded swf)
Copy link to clipboard
Copied
if you can add the full code (load + unload) maybe that will help to find out the wrong.
Copy link to clipboard
Copied
Here is my full test project code:
public class LoaderTest extends Sprite
{
private var _button:Sprite;
private var _link:String = "EmptyProj.swf";
private var _loader:Loader;
private var _url:URLRequest;
private var _removeButton:Sprite;
public function LoaderTest()
{
_url = new URLRequest(_link);
_button = new Sprite();
buttonGen(_button, 0xCCCCCC);
this.addChild(_button);
_button.x = 20;
_button.y = 20;
_button.addEventListener(MouseEvent.CLICK, onClick);
_removeButton = new Sprite();
buttonGen(_removeButton, 0xFF0000);
_removeButton.x = 20;
_removeButton.y = 20;
_removeButton.addEventListener(MouseEvent.CLICK, remove);
}
protected function remove(event:MouseEvent):void
{
if (_loader.numChildren>0)
_loader.removeChildren(0,_loader.numChildren-1);
_loader.unload();
_loader.stopAllMovieClips();
_loader.unloadAndStop(true);
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onComplete);
this.removeChild(_loader);
_loader = null;
this.removeChild(_removeButton);
this.addChild(_button);
}
protected function onComplete(event:Event):void
{
this.addChild(_loader);
this.addChild(_removeButton);
this.removeChild(_button);
}
private function buttonGen(butt:Sprite, color:uint):void
{
butt.graphics.beginFill(color);
butt.graphics.drawRect(0,0,200,80);
butt.graphics.endFill();
}
protected function onClick(event:MouseEvent):void
{
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
_loader.load(_url);
}
}
EmptyProj.swf code here
public class EmptyProj extends Sprite
{
public function EmptyProj()
{
}
}
Copy link to clipboard
Copied
function remove(event:MouseEvent):void
{
if (_loader.numChildren>0)
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onComplete);
_loader.unloadAndStop(true);
_loader = null;
}
it's working perfectly!
for tens of times I am loading and unloading a big swf file with hundreds of code lines and nothing is wrong there!
Copy link to clipboard
Copied
No need to stop the movie clips and to remove them.. use unloadAndStop() and it'll stop everything and unload the file.. as it's not possible to call the loader contents (the movieClips) to stop after unload method, it's already removed.. So try to use that 3 lines only to unload the file.
Copy link to clipboard
Copied
Thank you for your help. It is working for EmptyProj.swf. Looks like now I have to kill everything in real big project (I was killing nearly everithing, but seems like something remained), so that it should work for it too.
Copy link to clipboard
Copied
You're welcome my friend.
Copy link to clipboard
Copied
you can remove and change whatever you want on load complete..
the code above is working well but maybe you have to try.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now