# Dynamically loaded .jpg's into buttons

**URL:** https://forum.kirupa.com/t/dynamically-loaded-jpgs-into-buttons/243280
**Category:** flash
**Created:** [November 5, 2007, 11:47am UTC](https://forum.kirupa.com/t/dynamically-loaded-jpgs-into-buttons/243280 "2007-11-05T11:47:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Ubermeowmix](https://avatars.discourse-cdn.com/v4/letter/u/7cd45c/32.png) [@Ubermeowmix](https://forum.kirupa.com/u/Ubermeowmix)
#### Post date: [November 5, 2007, 11:47am UTC](https://forum.kirupa.com/t/dynamically-loaded-jpgs-into-buttons/243280/1 "2007-11-05T11:47:22Z")

</div>

I’m having a hard time taking the .jpg’s that I have loaded into movie clips and turning them into buttons. Does anyone know why my second for loop isn’t creating code for the movies? Help will be greatly appreciated.

The code I’m using:

//load the photo’s into arrays  
thumblist=‘thumb0.jpg, thumb1.jpg, thumb2.jpg, thumb3.jpg’;  
imagelist=‘pic0.jpg, pic1.jpg, pic2.jpg, pic3.jpg’;

//split the arrays up into lists that are passes to another total array.  
var thumbarray:Array = thumblist.split(", “);  
var imagearray:Array = imagelist.split(”, ");

//start looping and creating movie clips containing the array’d photos  
for(var i=0;i\<thumbarray.length;i++){  
//load the photos from the array into the photo boxes  
\_root[‘thumb’+i].loadMovie(‘thumbs/’+thumbarray\*, thumb\*);  
\_root[‘thumb’+i].\_width = 25;  
\_root[‘thumb’+i].\_height = \_root[‘thumb’+i].\_width;  
}  
//create a button function for each one loaded  
for (var j=0;j\<thumbarray.length;j++){  
//\_root[‘thumb’+j].useHandCursor = true;  
\_root[‘thumb’+j].onRelease = function () {  
startloading(‘images/pic’+j+’.jpg’, imageLoader);  
infofield.\_visible = true;  
}  
}  
//preloader  
function startLoading(currentimage){  
loadMovie(currentimage, imageLoader);  
\_root.onEnterFrame = function(){  
infoloaded = imageLoader.getBytesLoaded();  
infototal = imageLoader.getBytesTotal();  
percentage = Math.floor(infoloaded/infototal\*100);  
infofield.text = percentage+"%";  
if(percentage\>=100){  
delete this.onEnterFrame;  
infofield.\_visible = false;  
}  
}  
}
