Hi,
Real novice here, I have an xml gallery that works just fine my only problem is that i have no way to show the user the load progress between each image. Being as rubbish as I am I cant update my code to indicate this.
Im sure that someone here will find this challenge really quite easy. It would be a massive help and I would be sincerely grateful if someone would.
I have placed my code beneath for anyone willing. I have also highlighted where my when my photo loads (i think). Thought I would add the whole code just in case it was needed.
I would like something as simple as this below for each image, this is what I use to load the whole gallery
bytes_loaded = Math.round(_root.getBytesLoaded());
bytes_total = Math.round(_root.getBytesTotal());
getPercent = bytes_loaded/bytes_total;
_root.loadBar._width = getPercent*1020;
_root.loadText = Math.round(getPercent*100)+"%";
if (bytes_loaded == bytes_total) {
_root.gotoAndStop(3);
}
big appreciation
Reece.
the code:
nxt_btn._visible = false;
prv_btn._visible = false;
menuRight_btn._visible = true;
menuLeft_btn._visible = false;
photos_xml = new XML();
photos_xml.onLoad = init;
photos_xml.load("gallery/projects.xml");
photos_xml.ignoreWhite = true;
var photocontainer:MovieClip = _root.attachMovie("bigImage_mc", "photocontainer", this.getNextHighestDepth());
photocontainer._x = 0;
photocontainer._y = 39;
var mcLoader:MovieClipLoader = new MovieClipLoader();
var thumbLoader:MovieClipLoader = new MovieClipLoader();
var mcListener:Object = new Object();
var thumbListener:Object = new Object();
var firstLook:Boolean = true;
var menuButtons:MovieClip = menu_mc.holder_mc;
var galleryMask:MovieClip = menu_mc.mask_mc;
var menuRight:Button = menuRight_btn;
var menuLeft:Button = menuLeft_btn;
galleryMask._width = 700;
var menuSpeed:Number = 10;
function init(success) {
if (success == true) {
rootNode = photos_xml.firstChild;
// create gallery buttons
btngap = 0;
for (i=0; i<rootNode.childNodes.length; i++) {
//trace(btngap);
_root.menu_mc.holder_mc.attachMovie("samplebtn","samplebtn"+i,i,_root.menu_mc.holder_mc.getNextHighestDepth());
_root.menu_mc.holder_mc["samplebtn"+i]._x = btngap;
_root.menu_mc.holder_mc["samplebtn"+i]._y = 0;
btngap += 100;
var galleryTitle = _root.menu_mc.holder_mc["samplebtn"+i].btntext.text=rootNode.childNodes*.attributes.title;
_root.menu_mc.holder_mc["samplebtn"+i].btnindex = i;
_root.menu_mc.holder_mc["samplebtn"+i].btntext.text = galleryTitle;
_root.menu_mc.holder_mc["samplebtn"+i].onRollOver = function() {
//trace(this.btnindex);
this.gotoAndStop(2);
};
_root.menu_mc.holder_mc["samplebtn"+i].onRollOut = function() {
//trace(this.btnindex);
this.gotoAndStop(1);
};
_root.menu_mc.holder_mc["samplebtn"+i].onRelease = function() {
//trace(this.btnindex);
this.gotoAndStop(1);
loadGallery(this.btnindex);
};
menuLeft.enabled = false;
enableGalleryNavigation();
nxt_btn._visible = true;
prv_btn._visible = true;
menuRight_btn._visible = true;
menuLeft_btn._visible = false;
about_btn._visible = true;
illTitle_mc._visible = false;
desc_mc._visible = false;
choose_mc._visible = false;
}
// load first gallery
totalPhotos = rootNode.firstChild.childNodes.length;
firstPhotoNode = rootNode.firstChild.childNodes[0];
currentPhotoNode = firstPhotoNode;
currentIndex = 1;
loadPhoto(firstPhotoNode);
loadThumbs(0);
loadText(0);
loadTitle(0);
}
}
function loadGallery(galindex) {
totalPhotos = rootNode.childNodes[galindex].childNodes.length;
firstPhotoNode = rootNode.childNodes[galindex].childNodes[0];
currentPhotoNode = firstPhotoNode;
currentIndex = 1;
loadPhoto(firstPhotoNode);
loadThumbs(galindex);
loadText(galindex);
loadTitle(galindex);
}
function loadDesc(newDesc) {
descsrc = newDesc.attributes.desc;
_root.desc_mc.desc_txt.text = descsrc;
}
[COLOR="SeaGreen"]function loadPhoto(newPhotoNode) {
photosrc = newPhotoNode.attributes.src;
fadeouttween = new mx.transitions.Tween(photocontainer, "_alpha", easetype, 100, 0, 6, false);
fadeouttween.onMotionFinished = function() {
mcLoader.loadClip(photosrc,photocontainer);
};
mcListener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number) {
var loaderframe = Math.round((bytesLoaded/bytesTotal*100)/2);
loader.gotoAndStop(loaderframe);
};
mcListener.onLoadInit = function(target_mc:MovieClip) {
loader.gotoAndStop(1);
fadein = new mx.transitions.Tween(photocontainer, "_alpha", easetype, 0, 100, 6, false);
};
mcLoader.addListener(mcListener);[/COLOR]
}
function loadThumbs(galindex) {
// delete all thumbs
for (i=0; i<50; i++) {
removeMovieClip("thumbcontainer"+i);
}
// create empty movie clips and load thumb images
var columncount = 37;
var rowcount = 25;
for (i=0; i<totalPhotos; i++) {
var thumbHolder = _root.createEmptyMovieClip("thumbcontainer"+i, 100+i);
thumbHolder._x = columncount*20;
thumbHolder._y = rowcount*20;
columncount++;
if (columncount>47) {
columncount = 37;
rowcount++;
}
thumbsrc = photos_xml.firstChild.childNodes[galindex].childNodes*.attributes.thumb;
thumbLoader.loadClip(thumbsrc,this["thumbcontainer"+i]);
// last load -> enable buttons
if (i == totalPhotos-1) {
thumbListener.onLoadInit = function(target_mc) {
enableButtonsOther(galindex);
};
thumbLoader.addListener(thumbListener);
}
}
}
function loadTitle(galindex) {
galleryTitle = photos_xml.firstChild.childNodes[galindex].attributes.title;
about_btn.title_txt.text = galleryTitle;
}
function loadText(galindex) {
galleryText = photos_xml.firstChild.childNodes[galindex].attributes.intro;
prjct_desc.desc_txt.text = galleryText;
}
function enableButtonsOther(galindex) {
for (i=0; i<totalPhotos; i++) {
var thumb:MovieClip = _root["thumbcontainer"+i];
thumb.photonode = photos_xml.firstChild.childNodes[galindex].childNodes*;
thumb.onRelease = function() {
currentPhotoNode = this.photonode;
loadPhoto(this.photonode);
};
}
}
function enableGalleryNavigation():Void {
menuRight_btn.onPress = function() {
if (firstLook) {
menuLeft_btn._alpha = 100;
menuLeft_btn.enabled = true;
menuLeft_btn._visible = true;
firstLook = false;
}
var menuTop:Number = menuButtons._width-Math.abs(menuButtons._x)+100;
if (menuButtons._x<=0 && menuTop>=galleryMask._width+100) {
var targetPos:Number = menuButtons._x-galleryMask._width+100;
menuRight_btn.enabled = false;
menuLeft_btn.enabled = false;
menuButtons.onEnterFrame = function() {
menuButtons._x += (targetPos-menuButtons._x)/menuSpeed;
if (menuButtons._x<=(targetPos+0.8)) {
menuButtons._x = Math.round(targetPos);
//delete menuButtons.onEnterFrame;
menuRight_btn.enabled = true;
menuLeft_btn.enabled = true;
}
};
}
};
menuLeft_btn.onPress = function() {
var menuTop:Number = menuButtons._width-Math.abs(menuButtons._x)-100;
if (menuButtons._x<0 && menuTop>=0) {
var targetPos:Number = menuButtons._x+galleryMask._width-100;
menuRight_btn.enabled = false;
menuLeft_btn.enabled = false;
menuButtons.onEnterFrame = function() {
menuButtons._x += (-menuButtons._x+targetPos)/menuSpeed;
if (menuButtons._x>=(targetPos-0.8)) {
menuButtons._x = Math.round(targetPos);
//delete menuButtons.onEnterFrame;
menuRight_btn.enabled = true;
menuLeft_btn.enabled = true;
}
};
}
};
}
nxt_btn.onRollOver = function() {
this.gotoAndStop(2);
};
nxt_btn.onRelease = function() {
this.gotoAndStop(2);
nextPhotoNode = currentPhotoNode.nextSibling;
nextTitle = currentTitle.nextSibling;
nextDesc = currentDesc.nextSibling;
if (nextPhotoNode == null) {
break;
} else {
currentIndex++;
loadPhoto(nextPhotoNode);
currentPhotoNode = nextPhotoNode;
currentTitle = nextTitle;
loadTitle_ill(nextTitle);
currentDesc = nextDesc;
loadDesc(nextDesc);
}
};
nxt_btn.onRollOut = function() {
this.gotoAndStop(1);
};
prv_btn.onRelease = function() {
this.gotoAndStop(2);
previousTitle = currentTitle.previousSibling;
previousPhotoNode = currentPhotoNode.previousSibling;
previousDesc = currentDesc.previousSibling;
if (previousPhotoNode == null) {
break;
} else {
currentIndex--;
currentPhotoNode = previousPhotoNode;
loadPhoto(previousPhotoNode);
currentTitle = previousTitle;
loadTitle_ill(previousTitle);
currentDesc = previousDesc;
loadDesc(previousDesc);
}
};
prv_btn.onRollOver = function() {
this.gotoAndStop(2);
};
prv_btn.onRollOut = function() {
this.gotoAndStop(1);
};