# Coupling a picture load with function call

**URL:** https://forum.kirupa.com/t/coupling-a-picture-load-with-function-call/323794
**Category:** Uncategorized
**Created:** [July 18, 2011, 7:57pm UTC](https://forum.kirupa.com/t/coupling-a-picture-load-with-function-call/323794 "2011-07-18T19:57:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Tifarit](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@Tifarit](https://forum.kirupa.com/u/Tifarit)
#### Post date: [July 18, 2011, 7:57pm UTC](https://forum.kirupa.com/t/coupling-a-picture-load-with-function-call/323794/1 "2011-07-18T19:57:08Z")

</div>

Hi,

in my flash, I have an interface which loads pictures through button clicks. During the “loading stage” of every picture, a preloader animation is displayed.  
Currently, after the swf starts, the first picture is loaded without said preloader animation. I wish to call the preloader function (see code example below) ONCE during startup of the swf, with the first picture load.  
I’m sure this is an easy one for you guys 🙂  
Thanks in advance!

loadMovie(“load/beach.jpg”, \_root.content\_mc);

// image 1 loads the beach image using startPreload  
image1\_btn.onPress = function(){  
startPreload(“load/beach.jpg”);  
}

// image 2 loads the building image using startPreload  
image2\_btn.onPress = function(){  
startPreload(“load/building.jpg”);  
}

// this function begins preloading a swf url  
function startPreload(url){

```
// assign the url to the preloader 
// it will load it internally
preloader_mc.url = url;

// set destination movie clip for loaded content
preloader_mc.target = content_mc;

// begin the transition by playing frame 2
preloader_mc.gotoAndPlay(2);

```

}
