Possible to scale image loaded from xml?

Hi all,

I am using Sen’s xml photo gallery tutorial (link here ) 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:


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:

You can scale them after they fully loaded:)

scotty(-:

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

:hr:

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

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

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. :slight_smile:

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 :wink: ).

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:

Hmm, try

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

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:

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

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! :smiley:

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

I think this will work:

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

Yahoo! :thumb:

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

Thanks my man. :hr:

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

scotty(-:

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

:wink:

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:

Okay well I got the thumbs loading nicely (thanks again Scotty :wink: ) 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:

image_mc.loadMovie(this.IMAGE);

to this:

image_mc.loadPic(this.IMAGE);

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


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:

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

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

button 2 has

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:

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

scotty(-:

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

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

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

Hope that works:)

scotty(-:

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: