Loading different external swfs to the same movieclip

Hello and thank you for reading!

Here’s what i’m trying to do:

I have 3 different movieclips that acts as buttons. These 3 buttons are called mc_projekt1, mc_projekt2 and mc_projekt3.

When one of the buttons are clicked, they will load an external swf.

Here’s my code for doing this with the first button (mc_projekt1):

// Projekt1
content.mc_projekt1.addEventListener(MouseEvent.CLICK, projekt1);

function projekt1(e:Event):void{
    
var imageLoader:Loader;

function loadImage(url:String):void {
// Show Preloader
    preloader_projekt1.visible = true;
    
// Set properties on my Loader object
    imageLoader = new Loader();
    imageLoader.load(new URLRequest(url));
    imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
    mc_back.addEventListener(MouseEvent.CLICK, unload_p1);
}

loadImage("galleri1.swf");

function imageLoaded(e:Event):void {
// Load Image
    mc_projekt1.addChild(imageLoader);
    mc_back.visible = true;
    projekt1_tal1.visible = true;
    projekt1_text.visible = true;

// Hide Preloader
    preloader_projekt1.visible = false;
}

function imageLoading(e:ProgressEvent):void {
// Get current download progress
    var loaded:Number = e.bytesLoaded / e.bytesTotal;
// Send progress info to "preloader" movie clip
    preloader_projekt1.SetProgress(loaded);
}

// Unload
function unload_p1(event:Event):void
{
    imageLoader.unloadAndStop();
    projekt1_text.visible = false;
    mc_back.visible = false;
    }
}

This works fine and all, but what I’m doing right now is repeating the code above for each of the 3 buttons (mc_projekt1, mc_projekt2, mc_projekt3) and just simply add a “2” after each function instead. So for mc_projekt2, it’s imageLoader2 and loadImage2 etc. This also works fine, but I know I’ll be adding more buttons over time and in the end I’ll end up with a lot of the same code that way.

So I was wondering if by adding mc_projekt1, mc_projekt2 and mc_projekt3 and any future “mc_projekt” to an array this could all be done much simpler, I’m just not sure what to do …

Any help is much appreciated. If you can redirect me to a topic with a similar problem I’d be grateful as well.

Oh, and if I haven’t explained my problem enough, please also say so :slight_smile:

Thank you!