# Load images

**URL:** <https://forum.kirupa.com/t/load-images/14854>\
**Category:** flash\
**Created:** [March 3, 2003, 6:16pm UTC](https://forum.kirupa.com/t/load-images/14854 "2003-03-03T18:16:35Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![thorseye](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/thorseye/32/66_2.png) [@thorseye](https://forum.kirupa.com/u/thorseye)\
**Post date:** [March 3, 2003, 6:16pm UTC](https://forum.kirupa.com/t/load-images/14854/1 "2003-03-03T18:16:35Z")

</div>

Hello,  
I’m trying to figure out how this thing is working. I’m loading images with a script, I rescale them and then I want to change their position so they are spreading horizontally with let’s say 5 px space.  
How is this to be done? I don’t know if this is right, but I’ve done this script, and it’s working as far as to the second picture. The first picture is placed at 0px as it should, but the others is placed right beside the first picture, all at the same place. What’s wrong and what’s the proper solution?  
My script:

```php
for (i = 1; i < 11; i++) {
	duplicateMovieClip("tomt", "tomt"+i, i);
	loadMovie(i+".jpg", "tomt"+i);
	_root["tomt"+i]._width = 50;
	_root["tomt"+i]._height = 50;
	if (i == 1) {
		_root["tomt"+i]._x = 0;
	}
	else {
		_root["tomt"+i]._x = _root["tomt"+i-1]._x + 50;
	}
}

```

---

<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:** [March 3, 2003, 7:20pm UTC](https://forum.kirupa.com/t/load-images/14854/2 "2003-03-03T19:20:29Z")

</div>

Well why don’t you start at 0 instead of using an if statement?

```php
for (i = 0; i < 11; i++) {
    duplicateMovieClip("tomt", "tomt"+i, i);
    _root["tomt"+i].loadMovie(i+".jpg");
    _root["tomt"+i]._width = 50;
    _root["tomt"+i]._height = 50;
    _root["tomt"+i]._x = i*50;
  
}

```

Then to move it, of course the others overlap because you are going by the original clips X position so all the other ones after that will be at 50.

Instead you multiply “i” by 50 to get it moving.

---

<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:** [March 3, 2003, 7:33pm UTC](https://forum.kirupa.com/t/load-images/14854/3 "2003-03-03T19:33:13Z")

</div>

Ah of course 🙂 I’m still a code newbie…  
Is it possible to set a relative width/height instead of exact pixel values? Like 20% or so?

---

<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:** [March 3, 2003, 7:36pm UTC](https://forum.kirupa.com/t/load-images/14854/4 "2003-03-03T19:36:58Z")

</div>

Yes…

\_xscale and \_yscale resize according to a percentage.

\_width and \_height resize according to an exact pixel value.

---

<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:** [March 3, 2003, 7:57pm UTC](https://forum.kirupa.com/t/load-images/14854/5 "2003-03-03T19:57:12Z")

</div>

You’re the man… =)  
Hmmm. If I want to change the y value of the images when one image’s \_x value gets past 400 px, how should I do?

---

<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:** [March 3, 2003, 8:26pm UTC](https://forum.kirupa.com/t/load-images/14854/6 "2003-03-03T20:26:33Z")

</div>

Hrmph… Not sure. I did it before. I believe I used a while loop :-\

Can’t remember at this moment.

---

<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:** [March 3, 2003, 8:36pm UTC](https://forum.kirupa.com/t/load-images/14854/7 "2003-03-03T20:36:33Z")

</div>

I tried to use a while-loop, but I must have done wrong, because flash crashed… =)  
I tried using this code:

```php
for (i = 0; i < 11; i++) {
    duplicateMovieClip("tomt", "tomt"+i, i);
    _root["tomt"+i].loadMovie(i+".jpg");
	_root["tomt"+i]._xscale = 15;
    _root["tomt"+i]._yscale = 15;
	_root["tomt"+i]._x = i*_root["tomt"+i]._width;
	if (_root["tomt"+i]._x > 400 - _root["tomt"+i]._width) {
		_root["tomt"+i]._y += _root["tomt"+i]._height;
		_root["tomt"+i]._x = (i+1)*_root["tomt"+i]._width - 400;
	}  
}

```

Then it looks like [this](http://kastman.mine.nu/tosse/stuff/laddabilder.swf). Why is there whitespace between the images, and how should i do to set the first pictures \_x value to the same as the one above and then continue with the others just like above?

---

<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:** [March 3, 2003, 8:54pm UTC](https://forum.kirupa.com/t/load-images/14854/8 "2003-03-03T20:54:43Z")

</div>

Alright, I just gave it a test, I did use a while loop.

```php
for (i=0; i<11; i++) {
	tomt.duplicateMovieClip("tomt"+i, i);
	pic = _root["tomt"+i];
	pic.loadMovie(i+".jpg");
	pic._width = 50;
	pic._height = 50;
	pic._x = i*50;
	while (pic._x>=400) {
		pic._x -= 400;
		pic._y += 50;
	}
}

```

Try that. I used a variable to hold the \_root[“tont”+i] because lets admit… its pain retyping all of that :-\

[edit] and the space is probably caused because your images aren’t 50px wide so moving it 50px on the \_x axis is too much.

---

<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:** [March 3, 2003, 9:01pm UTC](https://forum.kirupa.com/t/load-images/14854/9 "2003-03-03T21:01:43Z")

</div>

Haven’t tested the script yet, but the thing about the spaces:  
As you see in the previous script i used \_width instead of 50 px to place the images… So I don’t think it’s that. Or could it be that anyway?

---

<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:** [March 3, 2003, 9:03pm UTC](https://forum.kirupa.com/t/load-images/14854/10 "2003-03-03T21:03:32Z")

</div>

Well I thought you were using \_xscale and \_yscale instead? In that case it wouldn’t be 50 px if you used 50.

I switched the width and height of my movie clip to 50 (I used a block square to test) and it becomes a seamless giant black box with no spaces.

---

<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:** [March 3, 2003, 9:25pm UTC](https://forum.kirupa.com/t/load-images/14854/11 "2003-03-03T21:25:59Z")

</div>

Yes that’s what I meant I think =)  
The while loop runs smooth, thanks! =) But, I’ve still got the problem with the space. Can’t figure out why it looks like this!? I am using \_xscale and \_yscale. Watch the [link](http://kastman.mine.nu/tosse/stuff/laddabilder.swf)I also want the pictures to be placed at the same \_x on all lines. Like if you set the first pic on the second row to pic0.\_x and then the rest of the pics follow the same pattern as before. Hope you get what I mean…

Current code goes here:

```php

for (i = 0; i < 11; i++) {
    tomt.duplicateMovieClip("tomt"+i, i);
	bild = _root["tomt"+i];
    bild.loadMovie(i+".jpg");
	bild._xscale = 15;
    bild._yscale = 15;
	bild._x = i*bild._width;
	while(bild._x >= 400) {
		bild._x -= 400;
		bild._y += bild._height;
	}
}

```

---

<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:** [March 3, 2003, 9:33pm UTC](https://forum.kirupa.com/t/load-images/14854/12 "2003-03-03T21:33:39Z")

</div>

Just change the 50 in i\*50 (from previous script) to a lower number to remove the space. Because using the \_width takes the original \_width of the image and not the \_xscale width (I believe).

And the reason it isn’t aligning correctly is because of the width of the images. It isn’t divisible correctly into 400 so it throws it off so you have to figure that out too.

---

<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:** [March 3, 2003, 9:41pm UTC](https://forum.kirupa.com/t/load-images/14854/13 "2003-03-03T21:41:24Z")

</div>

Yes I know that, but is there any way to bypass that? If I add pics with different widths it won’t look very nice if I use a exact value instead of \_width (or whatever that could replace that).  
So you don’t know any other solution to the thing about alignment? Well I must say that you’ve helped a lot already so I won’t bother you anymore =) Thanks

---

<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:** [March 3, 2003, 9:53pm UTC](https://forum.kirupa.com/t/load-images/14854/14 "2003-03-03T21:53:09Z")

</div>

Well the only thing I can think of that MIGHT work (hard to test since I don’t hav ea working example of clips with different widths) would be to get the width of the previous clip.

Try something like i\*\_root[“tomt”+(i-1)].\_xscale

In theory that should get the previous clips \_xscale and space by that, but I have no clue really.

I gotta go now sorry man.
