# Reuse code from 'Loading an External Image' tutorial

**URL:** <https://forum.kirupa.com/t/reuse-code-from-loading-an-external-image-tutorial/327815>\
**Category:** flash\
**Created:** [March 30, 2012, 1:43am UTC](https://forum.kirupa.com/t/reuse-code-from-loading-an-external-image-tutorial/327815 "2012-03-30T01:43:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mufflekid](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mufflekid](https://forum.kirupa.com/u/mufflekid)\
**Post date:** [March 30, 2012, 1:43am UTC](https://forum.kirupa.com/t/reuse-code-from-loading-an-external-image-tutorial/327815/1 "2012-03-30T01:43:24Z")

</div>

Sup, guys. I’m designing a portfolio website that will showcase artwork that could potentially take awhile to load, so I’m using the code from that tutorial:

```auto
var imageLoader:Loader; 
function loadImage(url:String):void {
    preloader.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);
}
loadImage("azuredragon.png");
 
function imageLoaded(e:Event):void {
// Load Image
imagearea.addChild(imageLoader);
preloader.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.SetProgress(loaded)
// Use it to get current download progress
// Hint: You could tie the values to a preloader :)
}

```

I’m using one of these, one image, per frame. I’ll be adding more and more in the future. I’m still a newbie to as3 and I haven’t completely understood the basics yet, so my question is this: how do I reuse the above code for a different frame without having to paste the entire thing with different names? I tried this:

```auto
trace(imageLoader);

loadImage("colorfulserpent.png");
 
imageLoaded();
 
imageLoading();

```

Of course, it didn’t work. Help?
