PDA

View Full Version : Please Help me with an XML gallery code problem



victord_21
November 25th, 2005, 03:03 PM
Hi. I need some help on a XML gallery code...The code is kindda' finished...well, kindda...The gallery is set to load like this:

It reads the XML to store the number of thumbnails that I want to group in 3 rows and stacks of 6 (subgalleries-movieclip from the library)...so I calculate the number of subgalleries.

Then I load the thumbnails in different instances of a movieclip from the library which I want to place in the subgallery using a function with attachMovie and if...else with different conditions.

The problem is that I can't get the attachMovie sintax right on function thumbnails_fn...It doesn't attach the movieclips from the library if I want to attach them to the subgallery...it works if I load them to the scene... :h: I can't figure out what I'm doing wrong.

Here's the code that I use:

function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
thumbnails = [];
albume = [];
total = xmlNode.childNodes.length;
if(total%6==0){
_root.r=Math.round(total/6);
}else{
_root.r=Math.round((total/6)+1);
}
for(j=0; j<_root.r; j++){
albums(j);
}
a1=0;
for (a2=0; a2<_root.r; a2++) {
CA=albume[a2];
trace(CA);
for (i=a1; i<a1+6; i++) {
if(i<total){
thumbnails[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
thumbnails_fn(i,CA);
}
}
a1+=6;
}
}else {
content = "file not loaded!";
}


}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("projects.xml");

/////////////////////Thumbnail Generator Code//////////////

function thumbnails_fn(k,CAlbum){
movie=this.CAlbum.attachMovie("obj", "obj"+k, 500+k);
if(k>0){
if((k)%3==0){
movie._x=0;
movie._y += thisY+80;
}else{
movie._x += thisX+120;
movie._y = thisY;
}
}else{
movie._x=0;
movie._y=0;
}
thisX=movie._x;
thisY=movie._y;
movie.thumbnail.loadMovie(thumbnails[k],movie.thumbnail.getNextHighestDepth());
}

/////////////////Album Generator Code//////////////

function albums(h){
albumMC=this.attachMovie("album", "album"+h, 50+h);
albume[h]= "album"+h;
albumMC._x=0;
albumMC._y += thisYalbum+200;
thisYalbum=albumMC._y;
}

Really appreciate any help I can get!

mathew.er
November 25th, 2005, 03:14 PM
it looks like CAlbum parameter in thumbnails_fn function is a string so you will need:
movie = this[CAlbum].attachMovie("obj", "obj"+k, 500+k);

victord_21
November 25th, 2005, 04:27 PM
it looks like CAlbum parameter in thumbnails_fn function is a string so you will need:
movie = this[CAlbum].attachMovie("obj", "obj"+k, 500+k);

WOOW! Thanks a lot Mathew!!! :))) Wow! That really worked! Thanks again!

mathew.er
November 25th, 2005, 04:38 PM
glad to help :)

victord_21
November 25th, 2005, 06:07 PM
it looks like CAlbum parameter in thumbnails_fn function is a string so you will need:
movie = this[CAlbum].attachMovie("obj", "obj"+k, 500+k);

I know I'm asking a lot of you but can you tell me why the following code doesn't work as I understand it should? It's the same code as before but I added an onRollOver, onRollOut and a preloader into the thumbnails_fn function but it seams to work only for the last thumbnail I mean that whichever thumbnail I roll over on still affects only the last one...I'm scratching my had over this one :h:


function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
thumbnails = [];
albume = [];
total = xmlNode.childNodes.length;
if(total%6==0){
_root.r=Math.round(total/6);
}else{
_root.r=Math.round((total/6)+1);
}
for(j=0; j<_root.r; j++){
albums(j);
}
a1=0;
for (a2=0; a2<_root.r; a2++) {
CA=albume[a2];
trace(CA);
for (i=a1; i<a1+6; i++) {
if(i<total){
thumbnails[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
thumbnails_fn(i,CA);
}
}
a1+=6;
}
}else {
content = "file not loaded!";
}


}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("projects.xml");

/////////////////////Thumbnail Generator Code//////////////

function thumbnails_fn(k,CAlbum){
movie=this.CAlbum.attachMovie("obj", "obj"+k, 500+k);
if(k>0){
if((k)%3==0){
movie._x=0;
movie._y += thisY+80;
}else{
movie._x += thisX+120;
movie._y = thisY;
}
}else{
movie._x=0;
movie._y=0;
}
thisX=movie._x;
thisY=movie._y;
movie.thumbnail.loadMovie(thumbnails[k],movie.thumbnail.getNextHighestDepth());
movie.onEnterFrame = function() {
filesize = movie.thumbnail.getBytesTotal();
loaded = movie.thumbnail.getBytesLoaded();
movie.preloader._visible = true;
if (loaded != filesize) {
movie.preloader._xscale = 100*loaded/filesize;
} else {
movie.preloader._visible = false;
}
}
}
movie.onRollOut=function(){
movie._alpha=100;
}
movie.onRollOver=function(){
movie._alpha=80;
}
}

/////////////////Album Generator Code//////////////

function albums(h){
albumMC=this.attachMovie("album", "album"+h, 50+h);
albume[h]= "album"+h;
albumMC._x=0;
albumMC._y += thisYalbum+200;
thisYalbum=albumMC._y;
}

mathew.er
November 25th, 2005, 06:28 PM
Please use [ as ] and [ /as ] (without spaces) tags to format code as actionscript. May I see your file? Its hard to judge just from staring on the code, Id like to try few thigs out...

victord_21
November 25th, 2005, 06:36 PM
Please use [ as ] and [ /as ] (without spaces) tags to format code as actionscript. May I see your file? Its hard to judge just from staring on the code, Id like to try few thigs out...

Sure, but I need to know how can I send you the source files...


function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
thumbnails = [];
albume = [];
total = xmlNode.childNodes.length;
if(total%6==0){
_root.r=Math.round(total/6);
}else{
_root.r=Math.round((total/6)+1);
}
for(j=0; j<_root.r; j++){
albums(j);
}
a1=0;
for (a2=0; a2<_root.r; a2++) {
CA=albume[a2];
trace(CA);
for (i=a1; i<a1+6; i++) {
if(i<total){
thumbnails[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
thumbnails_fn(i,CA);
}
}
a1+=6;
}
}else {
content = "file not loaded!";
}

}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("projects.xml");

/////////////////////Thumbnail Generator Code//////////////

function thumbnails_fn(k,CAlbum){
movie=this.CAlbum.attachMovie("obj", "obj"+k, 500+k);
if(k>0){
if((k)%3==0){
movie._x=0;
movie._y += thisY+80;
}else{
movie._x += thisX+120;
movie._y = thisY;
}
}else{
movie._x=0;
movie._y=0;
}
thisX=movie._x;
thisY=movie._y;
movie.thumbnail.loadMovie(thumbnails[k],movie.thumbnail.getNextHighestDepth());
movie.onEnterFrame = function() {
filesize = movie.thumbnail.getBytesTotal();
loaded = movie.thumbnail.getBytesLoaded();
movie.preloader._visible = true;
if (loaded != filesize) {
movie.preloader._xscale = 100*loaded/filesize;
} else {
movie.preloader._visible = false;
}
}
}
movie.onRollOut=function(){
movie._alpha=100;
}
movie.onRollOver=function(){
movie._alpha=80;
}
}

/////////////////Album Generator Code//////////////

function albums(h){
albumMC=this.attachMovie("album", "album"+h, 50+h);
albume[h]= "album"+h;
albumMC._x=0;
albumMC._y += thisYalbum+200;
thisYalbum=albumMC._y;
}

mathew.er
November 25th, 2005, 06:41 PM
you can upload fla to kirupa together with your post but you migth need to cut some graphics and stuff to lower size...

victord_21
November 25th, 2005, 06:53 PM
you can upload fla to kirupa together with your post but you migth need to cut some graphics and stuff to lower size...

Here they are...I hope it's ok...This is the test file I'm working on...

mathew.er
November 25th, 2005, 07:02 PM
Isnt it flash 8? Keeps saying "Unexpected file format"... you might need to "Save As" flash mx 2004 document or older...

victord_21
November 25th, 2005, 07:07 PM
Isnt it flash 8? Keeps saying "Unexpected file format"... you might need to "Save As" flash mx 2004 document or older...

Oh...I'm very sorry about that...I completly forgot...here they are again...

mathew.er
November 25th, 2005, 07:43 PM
For some reason I cant get it to work on thumbnail movie clip but all actions work on movie instance... just replace the old events with those...

movie.onRelease = function() {
getURL(links[k], "_blank");
};
movie.onRollOut = movie.onReleaseOutside = function() {
this._alpha = 100;
};
movie.onRollOver = function() {
this._alpha = 80;
};

victord_21
November 25th, 2005, 07:50 PM
For some reason I cant get it to work on thumbnail movie clip but all actions work on movie instance... just replace the old events with those...

movie.onRelease = function() {
getURL(links[k], "_blank");
};
movie.onRollOut = movie.onReleaseOutside = function() {
this._alpha = 100;
};
movie.onRollOver = function() {
this._alpha = 80;
};

GREAT! :D It works! Tanks again! :)