# unloadAndStop()

**URL:** <https://forum.kirupa.com/t/unloadandstop/329744>\
**Category:** flash\
**Created:** [October 9, 2012, 9:03pm UTC](https://forum.kirupa.com/t/unloadandstop/329744 "2012-10-09T21:03:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanDaMan](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@DanDaMan](https://forum.kirupa.com/u/DanDaMan)\
**Post date:** [October 9, 2012, 9:03pm UTC](https://forum.kirupa.com/t/unloadandstop/329744/1 "2012-10-09T21:03:49Z")

</div>

So I have a main swf that loads a child swf using the following code:

```auto

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.IEventDispatcher;
import flash.events.ProgressEvent;

var swfLoader:Loader;
var swfContent:MovieClip;
var loaded:Boolean=false;

stage.addEventListener(KeyboardEvent.KEY_UP, loadSWF);

function loadSWF(e:KeyboardEvent):void {
    if (e.keyCode!=32) return;
    if (!loaded) {
        var req:URLRequest=new URLRequest();
        req.url="test/LevelTest.swf";
        
        swfLoader=new Loader();
        setUpListeners(swfLoader.contentLoaderInfo);
        
        swfLoader.load(req);
    } else {
        unloadSWF();
    }
}

function setUpListeners(dispatcher:IEventDispatcher):void {
    dispatcher.addEventListener(Event.COMPLETE, addSWF);
    dispatcher.addEventListener(ProgressEvent.PROGRESS, preloadSWF);
}

function preloadSWF(e:ProgressEvent):void {
    var perc:int=(e.bytesLoaded/e.bytesTotal)*100;
}

function addSWF(e:Event):void {
    e.target.removeEventListener(Event.COMPLETE, addSWF);
    e.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
    
    swfContent=e.target.content;
    loaded=true;
    
    addChild(swfContent);
}

function unloadSWF():void {
    loaded=false;
    swfLoader.unloadAndStop();
    
    removeChild(swfContent);
    swfContent=null;
}

```

The idea is that the child swf is loaded upon pressing the spacebar, and then unloaded when you press it again. Every time I reload the swf, the frames per second drops significantly. I was under the impression that unloadAndStop() removes EVERYTHING, even the listeners. But this does not seem to be the case. What is the easiest way to completely remove everything from the child swf so it can be garbage collected? Do I just have write a destroy function for everything?
