# Possible to scale image loaded from xml?

**URL:** https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432
**Category:** Uncategorized
**Created:** [August 14, 2004, 7:29pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432 "2004-08-14T19:29:24Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 14, 2004, 7:29pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/1 "2004-08-14T19:29:24Z")

</div>

Hi all,

I am using Sen’s xml photo gallery tutorial ([link here](http://www.senocular.com/downloads/index.php?subaction=showfull&id=1074708580&archive=&start_from=&ucat=2&kind=2) ) which loads images, thumbnails, and text via xml (and some text files for lengthy photo descriptions).

I was wondering if it were possible to get properties like \_height or \_width of the thumbnails and then apply scaling to them. Long story short - I have both wide and tall thumbs and I want to put in an if statement that says if something is tall then scale it to be the same height as the wide ones but I am having trouble targeting the thumbs.

This is the code to load the thumbs:

```auto

for (child = 0; child < count; child++){
	currentThumb=menu_mc.createEmptyMovieClip("thumbnail"+child,child);
        //space the thumbs
	currentThumb._x = child * 60;
	image = currentThumb.createEmptyMovieClip("thumbnail_image",0);		
        //load the thumbs
        image.loadMovie(currentPicture.attributes.THUMB);
        //assign some other attributes
	currentThumb.NAME = currentPicture.attributes.NAME;
	currentThumb.IMAGE = currentPicture.attributes.IMAGE;
	currentThumb.TEXT = currentPicture.attributes.TEXT;
        //etc.

```

thanks for any help!

:hr:

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 14, 2004, 8:44pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/2 "2004-08-14T20:44:38Z")

</div>

You can scale them after they fully loaded:)

scotty(-:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 14, 2004, 9:09pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/3 "2004-08-14T21:09:40Z")

</div>

Hi Scotty! 🙂 But how do I reference them? I tried various combos of code after the loadMovie command but no go. Any ideas?

:hr:

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 14, 2004, 9:38pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/4 "2004-08-14T21:38:32Z")

</div>

I think you can use the code I gave you a few weeks ago:)

```auto
var a = 100;
for (child=0; child<count; child++) {
	currentThumb = menu_mc.createEmptyMovieClip("thumbnail"+child, child);
	//space the thumbs
	currentThumb._x = child*60;
	image = currentThumb.createEmptyMovieClip("thumbnail_image", 0);
	//load the thumbs
	image.loadMovie(currentPicture.attributes.THUMB);
	loadMeter(image);
	//assign some other attributes
	currentThumb.NAME = currentPicture.attributes.NAME;
	currentThumb.IMAGE = currentPicture.attributes.IMAGE;
	currentThumb.TEXT = currentPicture.attributes.TEXT;
	//etc. 
}
function loadMeter(clip) {
	tmp = this.createEmptyMovieClip("temp"+a, a++);
	tmp.onEnterFrame = function() {
		var tot = clip.getBytesTotal();
		trace(clip);
		var loa = clip.getBytesLoaded();
		if (tot == loa && tot>0 && clip._width>0 && clip._height>0) {
			//if it's a portrait picture, give it the heigth of a landscape one
			//in your case 75 and scale the width proportionally
			if (clip._height>=clip._width) {
				clip._height = 75;
				clip._xscale = clip._yscale;
			}
			delete this.onEnterFrame;
		}
	};
}

```

Didn’t test it, but give it a try;)

scotty(-:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 14, 2004, 9:39pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/5 "2004-08-14T21:39:37Z")

</div>

Ha ha, you know I tried bits and pieces of that but maybe didn’t get all the parts I needed. I’ll try it now. 🙂

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 14, 2004, 9:48pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/6 "2004-08-14T21:48:26Z")

</div>

Works brilliantly of course! :thumb: Knew I left out something . . .

But now here is a puzzle for you (or anyone else who wants to take a crack at it 😉 ).

Sen’s script has the thumbs loading into depths so the currentThumb, whichever it may be, gets it’s \_x property set to 60 pixels more than the last \_x coordinate, which means that there are gaps between images that aren’t the same size. Any idea how I can use the width of the previous thumb instead of a straight number like 60?

:hr:

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 14, 2004, 9:58pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/7 "2004-08-14T21:58:22Z")

</div>

Hmm, try

```auto
currentThumb._x = oldThumb._x+oldThumb._width+60;
oldThumb=currentThumb;

```

Maybe you have to set oldThumb.\_x and oldThumb.\_width to 0 outside the loop for the first thumb. Change the 60 to the gap you want:)

scotty(-:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 14, 2004, 10:30pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/8 "2004-08-14T22:30:34Z")

</div>

Hmm . . .doesn’t work. When I trace oldThumb.\_width I get 0, even without setting it outside the loop. Same with tracing the currentThumb.\_width.

:hr:

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 14, 2004, 10:43pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/9 "2004-08-14T22:43:41Z")

</div>

LOL, off course… stupid me :stunned: the width is set **after** it’s fully loaded.  
So we must set the thumbs after the if statement. It’s rather late now, if tomorrow no one else has helped you, i’ll give it a try:)

scotty(-:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 14, 2004, 11:33pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/10 "2004-08-14T23:33:03Z")

</div>

Thanks scotty! It’s hard with the xml stuff to know when the pics are loaded. I’d of thought that once the loadMovie command is executed then its good to go but I guess that is no guarantee in the processor world. I look forward to hearing more from you tomorrow! 😃

p.s. You probably can guess this but I’ll be working on getting the resize prototype to work in there too . . . 😛

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 16, 2004, 7:45am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/11 "2004-08-16T07:45:00Z")

</div>

I think this will work:

```auto
var a = 100;
for (child=0; child<count; child++) {
	currentThumb = menu_mc.createEmptyMovieClip("thumbnail"+child, child);
	image = currentThumb.createEmptyMovieClip("thumbnail_image", 0);
	image.loadMovie(currentPicture.attributes.THUMB);
	loadMeter(image);
	currentThumb.NAME = currentPicture.attributes.NAME;
	currentThumb.IMAGE = currentPicture.attributes.IMAGE;
	currentThumb.TEXT = currentPicture.attributes.TEXT;
	//etc. 
}
var ch = 0;
function loadMeter(clip) {
	tmp = this.createEmptyMovieClip("temp"+a, a++);
	tmp.onEnterFrame = function() {
		var tot = clip.getBytesTotal();
		var loa = clip.getBytesLoaded();
		if (tot == loa && tot>0 && clip._width>0 && clip._height>0) {
			ch++;
			if (ch == count) {
				placeThumbs();
			}
			if (clip._height>=clip._width) {
				clip._height = 75;
				clip._xscale = clip._yscale;
			}
			delete this.onEnterFrame;
		}
	};
}
var gap = 20;
function placeThumbs() {
	for (i=0; i<count; i++) {
		thb = this.menu_mc["thumbnail"+i];
		prevthb = this.menu_mc["thumbnail"+(i-1)];
		var space = prevthb._width+prevthb._x+gap;
		thb._x = space;		
	}
}

```

:thumb:

scotty(-:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 17, 2004, 2:52am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/12 "2004-08-17T02:52:34Z")

</div>

Yahoo! :thumb:

Lesson learned: break everything down into small functions that do only one task. KEEP IT SIMPLE!!

Thanks my man. :hr:

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 17, 2004, 7:06am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/13 "2004-08-17T07:06:24Z")

</div>

> [@lunatic](#):
>
> Lesson learned: break everything down into small functions that do only one task. KEEP IT SIMPLE!!

LOL, I’ll give you an A…  
no problem, lunatic;)

scotty(-:

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [August 17, 2004, 10:32am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/14 "2004-08-17T10:32:50Z")

</div>

you know, I re-did this file for the XML tutorial Im writing and I realized I spent too much time commenting so theres a few “errors” mostly things like variables that should be local but werent declared as being so etc. :!: Looks ike you guys got it all figured out though

😉

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 17, 2004, 2:12pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/15 "2004-08-17T14:12:32Z")

</div>

Never ever ever say “too much commenting”. I wouldn’t understand a lick of it without it! Looking forward to 43 pages more!! :thumb:

:beam:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 18, 2004, 2:36am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/16 "2004-08-18T02:36:00Z")

</div>

Okay well I got the thumbs loading nicely (thanks again Scotty 😉 ) and I even got the resize thing going and the finite menu for the thumbs all by my little 'ol self (this is truly impressive for those that know me).

Anyway, to get the resize to work I had to change this:

```auto
image_mc.loadMovie(this.IMAGE);

```

to this:

```auto
image_mc.loadPic(this.IMAGE);

```

loadPic is a prototype function from the resizing slideshow thread which is essentially:

```auto

MovieClip.prototype.loadPic = function(pic) {
	//uncommented next line 
	image_mc._alpha = 0;
	this.loadMovie(pic);
	//loadbar._visible = 1;
	this._parent.onEnterFrame = function() {
		var t = image_mc.getBytesTotal(), l = image_mc.getBytesLoaded();
		var percent = Math.round(100*l/t);
		if (t != 0 && Math.round(l/t) == 1 && image_mc._width>0 && image_mc._height>0) {
			var w = image_mc._width+spacing, h = image_mc._height+spacing;
			border.resizeMe(w, h);
			//loadbar._visible = 0;
			//loadertxt.text = " ";
			delete this.onEnterFrame;
		} else {
			//loadertxt.text = percent+" % loaded";
			//loadbar._width = percent;
		}
	};
};

```

I don’t have the preloader up yet so its commented out.

ANYWAY somehow I managed to lose the TEXT attribute from the xml file :hair: (see xml code at start of this thread). How did I do that? It was working fine (I think) before I changed the loadMovie to a call to a function.

Any hints on what to look out for would be splendid. :love:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 18, 2004, 3:19am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/17 "2004-08-18T03:19:36Z")

</div>

Okay and while I’m at it. I have 200 images and I am trying to load 20 at a time per xml file. So I have xmlgallery.xml, xmlgallery2.xml, xmlgallery3.xml, etc. I am calling the xml load function from buttons. So button 1 has

```auto
on(release){
	portfolioInfo.load("xmlgallery.xml");
}

```

button 2 has

```auto
on(release){
	portfolioInfo.load("xmlgallery2.xml");
}

```

etc.

If I click button1 it loads fine. If I click button2 only the very last thumb and pic load. If I click on button1 again I get nothing. If, from startup, I click button2 I get nothing?

What am I not understanding about how xml loads?

:hr:

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 18, 2004, 6:31am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/18 "2004-08-18T06:31:57Z")

</div>

Can you post your .fla/xml [size=1](or email)[/size]?

scotty(-:

---

<div class="post-metadata">

### Author: ![scotty](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@scotty](https://forum.kirupa.com/u/scotty)
#### Post date: [August 18, 2004, 10:03am UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/19 "2004-08-18T10:03:10Z")

</div>

I had a look at sen’s tut, I’m not sure but try this

```auto
function galleryChoice(choice) {
	//remove the previous thumbs
	removeOldThumbs(curThumbs);
	portfolioInfo = new XML();
	portfolioInfo.ignoreWhite = true;
	timeline = this;
	portfolioInfo.onLoad = function() {
		portfolioTag = this.firstChild;
		count = portfolioTag.childNodes.length;
		for (child=0; child<count; child++) {
			//
			//all your thumbnailcode here
			//
		}
	};
	var curThumbs = count;
	portfolioInfo.load(choice);
}
function removeOldThumbs(cur){
	for(i=0;i<cur;i++){
		this.menu_mc["thumbnail"+i].removeMovieClip();
	}
}

```

and for your button

```auto
on(release){
        _root.galleryChoice("xmlgallery.xml");
}

```

Hope that works:)

scotty(-:

---

<div class="post-metadata">

### Author: ![lunatic](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lunatic](https://forum.kirupa.com/u/lunatic)
#### Post date: [August 19, 2004, 2:52pm UTC](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432/20 "2004-08-19T14:52:53Z")

</div>

Ack! I would love to send you my files but I’m headed out of town (again, sigh) for a week so unfortunately I have to put it off :hair: until I get back.

:love: thanks scotty! :hugegrin:

[Next page](https://forum.kirupa.com/t/possible-to-scale-image-loaded-from-xml/119432.md?page=2)
