Stuck with loader in as3

Hi,

I have the below code on a frame in my timeline which loads an external swf. I just need to know what code I would need to add to a new frame so when that new frame is entered it unloads the below. When I try and unload it from a new frame it comes up with an error ‘1120: Access of undefined property l.’

If anyone could give me the code I need to do this I would be very grateful. Thanks!

import flash.net.URLLoader;
import flash.net.URLRequest;

loadGallery();

function loadGallery():void
{
var l:Loader = new Loader();
//load aMediaGallery.swf or aMediaGalleryFlashVar.swf
var req:URLRequest = new URLRequest(“aMediaGallery.swf”);
l.load(req);
l.contentLoaderInfo.addEventListener(Event.INIT, galleryLoaded);
l.y = 114;
l.x = 0;

}

function galleryLoaded(e:Event):void
{
addChild(e.target.loader);
e.target.loader.content.initGallery();
}