# Loading different external swfs to the same movieclip

**URL:** <https://forum.kirupa.com/t/loading-different-external-swfs-to-the-same-movieclip/309465>\
**Category:** Uncategorized\
**Created:** [May 16, 2010, 11:41am UTC](https://forum.kirupa.com/t/loading-different-external-swfs-to-the-same-movieclip/309465 "2010-05-16T11:41:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![neys](https://avatars.discourse-cdn.com/v4/letter/n/74df32/32.png) [@neys](https://forum.kirupa.com/u/neys)\
**Post date:** [May 16, 2010, 11:41am UTC](https://forum.kirupa.com/t/loading-different-external-swfs-to-the-same-movieclip/309465/1 "2010-05-16T11:41:58Z")

</div>

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):

```auto
// 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 🙂

Thank you!
