Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

centre image

Status
Not open for further replies.

Gazzieh

IS-IT--Management
Dec 18, 2006
117
GB
I have created a photo gallery that loads images into a movie clip via an xml document. By default the movie clip is sized for landscape images but if I load a portrait image it loads on the left of the movie clip. How can I get it to load centrally?

Code:
var my_xml = new XML();
my_xml.ignoreWhite = true;

PhotoPath = newPath;
PhotoFile = newFile;
Photonr = 0;
fadeSpeed = 30;

my_xml.onLoad = function(success) {
	if (success) {
		_global.file = [];
		_global.description = [];
		_global.photonr = 0;
		
		for (var i=0; i<my_xml .firstChild.childNodes.length; i++) {
			_global.file[i] = my_xml.firstChild.childNodes[i].attributes.file;
			_global.description[i] = my_xml.firstChild.childNodes[i].attributes.description;
		}
		_global.TotalNum = i;
		loadMovie(PhotoPath+"/"+_global.file[Photonr],photo);
		dynText.text=_global.description[Photonr];
	}
};

changePhoto = function(direct) {
	
	MaxPhoto = _global.TotalNum - 1;
	
	if (direct==-1) {
		switch(Photonr) {
			case 0:
				Photonr = MaxPhoto;
				break;
			default:
				Photonr = Photonr - 1;
		}
	} else {
		switch(Photonr) {
			case MaxPhoto:
				Photonr = 0;
				break;
			default:
				Photonr = Photonr + 1;
		}
	}
	
	onEnterFrame = fadeOut;
};

fadeOut = function() {
	if (photo._alpha>fadeSpeed) {
		photo._alpha -= fadeSpeed;
		frame._alpha -= fadespeed;
	} else {
		loadPhoto();
	}
};

loadPhoto = function() {
	loadMovie(PhotoPath+"/"+_global.file[Photonr],photo);
	dynText.text=_global.description[Photonr];
	onEnterFrame = loadMeter;
};

loadMeter = function() {
	var l, t;
	l = photo.getBytesLoaded();
	t = photo.getBytesTotal();
	if (t>0 && t == l) {
		onEnterFrame = fadeIn;
	} else {
		trace(l/t);
	}
};

fadeIn = function() {
	if (photo._alpha<100-fadeSpeed) {
		photo._alpha += fadeSpeed;
	} else {
		photo._alpha = 100;
		onEnterFrame = null;
	}
};

my_xml.load(newFile);
 
The easiest would probably be to create a new movie clip holder mc, in which you would nest your photo mc.

You then need to change all your paths to photo to holder_mc.photo instead...

Before loading a new picture, set the photo mc's alpha to 0...

loadPhoto = function() {
holder_mc.photo._alpha = 0;
loadMovie(PhotoPath+"/"+_global.file[Photonr],photo);
dynText.text=_global.description[Photonr];
onEnterFrame = loadMeter;
};

Then in the loadMeter function...

loadMeter = function() {
var l, t;
l = holder_mc.photo.getBytesLoaded();
t = holder_mc.photo.getBytesTotal();
if (t>0 && t == l) {
holder_mc.photo._x = holder_mc._width/2 - holder_mc.photo._width/2;
holder_mc.photo._y = holder_mc._height/2 - holder_mc.photo._height/2;
onEnterFrame = fadeIn;
} else {
trace(l/t);
}
};


Regards. FLASH HELP - OPENED FOR BUSINESS!
TO GET YOUR OWN FREE WEBSITE HOSTING
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top