# How to load external swf with using the child class

**URL:** <https://forum.kirupa.com/t/how-to-load-external-swf-with-using-the-child-class/331436>\
**Category:** flash\
**Created:** [August 1, 2013, 8:01am UTC](https://forum.kirupa.com/t/how-to-load-external-swf-with-using-the-child-class/331436 "2013-08-01T08:01:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashiharu](https://avatars.discourse-cdn.com/v4/letter/y/bb73d2/32.png) [@yashiharu](https://forum.kirupa.com/u/yashiharu)\
**Post date:** [August 1, 2013, 8:01am UTC](https://forum.kirupa.com/t/how-to-load-external-swf-with-using-the-child-class/331436/1 "2013-08-01T08:01:50Z")

</div>

[COLOR=#000000][FONT=Arial]I would like to load external child swf into the parent swf (under same directory). I did try, the child loaded but the class in it didn’t work.[/FONT][/COLOR]  
[COLOR=#000000][FONT=Arial]1) How can i load the class of child swf?[/FONT][/COLOR]  
[COLOR=#000000][FONT=Arial]2) How can i unload the class of child swf?(becoz there could be many ext. swf with different class)[/FONT][/COLOR]  
[COLOR=#000000][FONT=Arial]thx  
[/FONT][/COLOR]  
[COLOR=#000000][FONT=Arial]main.fla[/FONT][/COLOR]

```auto

function startLoad(){
    var mLoader:Loader = new Loader();
    var mRequest:URLRequest = new URLRequest("game1.swf");
    var mLoaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain);
    mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    mLoader.load(mRequest, mLoaderContext);
}
function onCompleteHandler(loadEvent:Event){
    var keyManager:Class = ApplicationDomain.currentDomain.getDefinition("net.keithhair.KeyManager") as Class;
    addChild(loadEvent.currentTarget.content);
}

```

[COLOR=#000000][FONT=Arial]game1.fla[/FONT][/COLOR]

```auto
import net.keithhair.KeyManager;
keyManager=new KeyManager(stage);
keyManager.addKey(["a"], doSomething);
function doSomething():void {
    //do something  
}

```

Result:

```auto

TypeError: Error #1009: Cannot access a property or method of a null object reference.at net.keithhair::KeyManager/removeListeners()
at net.keithhair::KeyManager/addListeners()
at net.keithhair::KeyManager()
at game1_fla::MainTimeline/frame1()

```
