Alright folks. A while back I got some help with making a movie clip draggable. I’ve got that working without any issues. However, I’m loading in some images via XML.
Each of these images will be placed within the draggable movieclip called imagecontainer_mc. I want to create a large horizontal image with each one placed next to each other. The user can drag through them instead of scrolling horizontally.
Here’s an example of how the site will look with static images.
http://www.defiancevisual.com/flashtest01.swf
I’ve got the XML in my flash document, and I’ve got loops that trace the image location and widths back to me.
http://www.defiancevisual.com/gallery/ is my XML.
I’m stuck when it comes to image placement. I think my approach to creating a movie clip and tossing an image in it all within imagecontainer_mc isn’t working. Could anyone point me in the right direction?
#include "lmc_tween.as"
//Make the stage fluid
Stage.align = 'TL';
Stage.scaleMode = 'noScale';
//Initialize image container
imagecontainer_mc._x = 0;
imagecontainer_mc._y = 0;
//imagecontainer_mc._y = ((Stage.height / 2) - (imagecontainer_mc._height / 2));
//Initialize menu items
logo_mc._y = 0;
logo_mc._x = 0;
navigation_mc._x = Stage.width - navigation_mc._width;
navigation_mc._y = 0;
music_mc._x = Stage.width - music_mc._width;
music_mc._y = Stage.height - music_mc._height;
tagline_mc._x = 0;
tagline_mc._y = Stage.height - tagline_mc._height;
//Place the items accordingly on resize
sizeListener = new Object();
sizeListener.onResize = function() {
imagecontainer_mc.tween("_y", ((Stage.height / 2) - (imagecontainer_mc._height / 2)), 1, "easeInOutExpo");
navigation_mc._x = Stage.width - navigation_mc._width;
music_mc._x = Stage.width - music_mc._width;
music_mc._y = Stage.height - music_mc._height;
tagline_mc._y = Stage.height - tagline_mc._height;
};
Stage.addListener(sizeListener);
//Set the variables of the drag physics
decel = .8;
ratio = .5;
padding = 100; //in pixels
var dragX:Number;
var dragY:Number;
//Keep the horizontal drag within the bounds of the stage
MovieClip.prototype.checkBounds = function () {
if (this._x <= Stage.width - imagecontainer_mc._width - (Stage.width - padding)) {
this._x = Stage.width - imagecontainer_mc._width - (Stage.width - padding);
}
if (this._x >= 0 + (Stage.width-padding)) {
this._x = 0 + (Stage.width-padding);
}
if (this._y >= Stage.height - padding) {
this._y = Stage.height - padding;
}
if (this._y <= 0 - (imagecontainer_mc._height - padding)) {
this._y = 0 - (imagecontainer_mc._height - padding);
}
};
imagecontainer_mc.onEnterFrame = function () {
if (!drag) {
this._x += xspeed *= decel;
this._y += yspeed *= decel;
} else {
x = this._x;
this._x = this._parent._xmouse - dragX;
y = this._y;
this._y = this._parent._ymouse - dragY;
}
this.checkBounds ();
};
imagecontainer_mc.onPress = function () {
dragX = this._xmouse;
dragY = this._ymouse;
drag = true;
};
imagecontainer_mc.onRelease = imagecontainer_mc.onReleaseOutside = function () {
drag = false;
xspeed = (this._x - x) * ratio;
yspeed = (this._y - y) * ratio;
this.checkBounds ();
};
oldx = _root._xmouse;
oldy = _root._ymouse;
function loadXML(loaded) {
if (loaded) {
albumsNode = this.firstChild.childNodes;
albumtotal = albumsNode.length;
albums = [];
//initialize p
p = 0;
for (a=0; a<albumtotal; a++) {
albums[a] = this.firstChild.childNodes[a].attributes.title;
//trace(albums[a]);
imagesNode = this.firstChild.childNodes[a].childNodes;
imagestotal = imagesNode.length;
imageurl = [];
imagewidth = [];
for (i=0; i<imagestotal; i++) {
imageurl* = this.firstChild.childNodes[a].childNodes*.attributes.url;
imagewidth* = this.firstChild.childNodes[a].childNodes*.attributes.width;
//trace(imagewidth*);
image();
}
}
} else {
trace("There was an error loading the file.");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://www.defiancevisual.com/gallery/");
function image() {
if (loaded == filesize) {
picturemcname = "image_mc" + i;
picture = imagecontainer_mc.createEmptyMovieClip(picturemcname, i);
picture.loadMovie(imageurl*);
//p = number(imagewidth*) * -1;
p = p + number(imagewidth*);
trace(p);
imagecontainer_mc.picturemcname._x = p;
}
}
Am I approaching this wrong?