Load images

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:

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;
	}
}

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

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.

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

Yes…

_xscale and _yscale resize according to a percentage.

_width and _height resize according to an exact pixel value.

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?

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

Can’t remember at this moment.

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

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. 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?

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

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.

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?

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.

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 linkI 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:


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;
	}
}

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.

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

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.