# \[fmx04\] loading images randomly and put them in \_x and \_y coordinates problem

**URL:** <https://forum.kirupa.com/t/fmx04-loading-images-randomly-and-put-them-in--x-and--y-coordinates-problem/59442>\
**Category:** flash\
**Created:** [July 31, 2004, 3:01pm UTC](https://forum.kirupa.com/t/fmx04-loading-images-randomly-and-put-them-in--x-and--y-coordinates-problem/59442 "2004-07-31T15:01:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxdido](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@maxdido](https://forum.kirupa.com/u/maxdido)\
**Post date:** [July 31, 2004, 3:01pm UTC](https://forum.kirupa.com/t/fmx04-loading-images-randomly-and-put-them-in--x-and--y-coordinates-problem/59442/1 "2004-07-31T15:01:22Z")

</div>

hi,

I have a problem with loading images randomly and putting them in the right \_x and \_y coordinates.  
I have a swf file with in the first frame a button with this code :

on (release) {  
filename = [“image-01.jpg”, “image-02.jpg”, “image-03.jpg”];  
path = “images/”;  
i = filename.length;  
k = Math.floor(Math.random()\*i);  
mctarget.loadMovie(path+filename[k]);  
gotoAndPlay(“intropreloadit”);  
}

in frame 10 I have this code for preloading the dynamically loaded image :

// set the movieclip invisible  
mctarget.\_visible = false  
// get the loaded and total bytes  
total = mctarget.getBytesTotal();  
loadedbytes = mctarget.getBytesLoaded();  
percentage = Math.floor((loadedbytes/total)\*100);  
// when dynamically loading, make sure you set getbytesLoaded()\>0  
if (mctarget.getBytesLoaded()\>0) {  
// set the progressbar  
mcprogressbar.\_xscale = percentage;  
// set the percentage dynamic textfield  
mcprogresstxt.perc = percentage+"%";  
} else {  
mcprogressbar.\_xscale = 0;  
mcprogresstxt.perc = 0+"%";  
mcprogresstxt.bytestotal = Math.floor(total/1000) + " KB";  
mcprogresstxt.bytesloaded = Math.floor(loadedbytes/1000) + " KB /";  
}

in frame 11 :

if (percentage == 100) {  
gotoAndStop(“introdoneloading”);  
} else {  
gotoAndPlay(“intropreloadit”);  
}

and in frame 12 :

// done loading image so now we can position the image.  
// centerpoint of the movieclip “mctarget” to be set as you wish.  
x = 640;  
y = 230;  
// now we get the size of the image  
introwidth = mctarget.\_width;  
introheight = mctarget.\_height;  
// finally, set new \_x and \_y position to center the image to the centerpoint  
mctarget.\_x = x-(introwidth/2);  
mctarget.\_y = y-(introheight/2);  
/\* ready with loading of the .jpg file --\> then set mctarget.\_visible = false of true \*/  
mctarget.\_visible = true  
stop();

the image gets loaded and placed correctly when played from the harddisk. the problem starts when i upload the swf to the internet, then the image won’t be centered but the left upper point of the image is placed at x=640 and y=230

what am I doing wrong?  
max.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 1, 2004, 8:46am UTC](https://forum.kirupa.com/t/fmx04-loading-images-randomly-and-put-them-in--x-and--y-coordinates-problem/59442/2 "2004-08-01T08:46:59Z")

</div>

when I click on the button I tell the flashplayer to --\> gotoAndPlay(“intropreloadit”);  
now I changed this to --\> gotoAndPlay(9);

frame 9 is 1 frame before framelabel “intropreloadit” apparently flash needs 1 frame to figure out what image needs to be loaded, I think. I could solve it by adding one more frame, but I have the feeling that there’s a better way of doing this.

can anyone help me out with this.
