Hey all, I’m a complete newbie when it comes to actionscript. I took the basic image gallery tutorial on this site and messed about with the code a bit so that the images move back and fourth rather than fading in and out. I’m sure there are better ways to do that than how I did, but it mostly works so I’m happy. My problem now is that I don’t know how to make the center of the photos align to the center of the stage. I can of course allign the first one, so it starts aligned, but as soon as I start scrolling through images it aligns the left side of the image to the center of the stage, any help would be much apreciated.
thanks
// variables ------------------------------------------
// put the path to your pics here, include the slashes (ie. "pics/")
// leave it blank if they're in the same directory
this.pathToPics = "images/";
// fill this array with your pics
this.pArray = ["ITT1.jpg", "ITT2.jpg", "ITT3.jpg", "ITT4.jpg"];
this.fadeSpeed = 50;
this.pIndex = 0;
var dir;
// MovieClip methods ----------------------------------
// d=direction; should 1 or -1 but can be any number
//loads an image automatically when you run animation
loadMovie(this.pathToPics+this.pArray[0], _root.photo);
MovieClip.prototype.changePhoto = function(d) {
// make sure pIndex falls within pArray.length
this.pIndex = (this.pIndex+d)%this.pArray.length;
if (this.pIndex<0) {
this.pIndex += this.pArray.length;
}
if (d<0) {
dir = "Back";
} else {
dir = "Forward";
}
this.onEnterFrame = fadeOut;
if (d<0) {
this.onEnterFrame = fadeOutR};
};
MovieClip.prototype.fadeOut = function() {
if (this.photo._x>-575) {
this.photo._x -= this.fadeSpeed;
} else {
this.loadPhoto();
}
};
MovieClip.prototype.fadeOutR = function() {
if (this.photo._x<575) {
this.photo._x += this.fadeSpeed;
} else {
this.loadPhoto();
}
};
MovieClip.prototype.loadPhoto = function() {
// specify the movieclip to load images into
var p = _root.photo;
//------------------------------------------
//start alpha
if (dir == "Forward") {
p._x = 575;
} else {
p._x = -575;
}
p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
var i, l, t;
l = this.photo.getBytesLoaded();
t = this.photo.getBytesTotal();
if (t>0 && t == l && dir == "Forward") {
this.onEnterFrame = fadeIn;
} if (t>0 && t == l && dir != "Forward") {
this.onEnterFrame = fadeInR;
}
};
MovieClip.prototype.fadeIn = function() {
if (this.photo._x>Stage.width/2) {
this.photo._x -= this.fadeSpeed;
} else {
this.photo._x = Stage.width/2;
this.onEnterFrame = null;
}
};
MovieClip.prototype.fadeInR = function() {
if (this.photo._x<Stage.width/2) {
this.photo._x += this.fadeSpeed;
} else {
this.photo._x = Stage.width/2;
this.onEnterFrame = null;
}
};
// Actions -----------------------------------------
// these aren't necessary, just an example implementation
this.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
this.changePhoto(-1);
} else if (Key.getCode() == Key.RIGHT) {
this.changePhoto(1);
}
};
Key.addListener(this);