Hi, I have a function where i load some images from an XML file. The function builds up a pattern with boxes in lines of 4, and for each Image-tag in the XML file, it creates a new box in that pattern and loads an image into it. The problem is that as the code is written now, all the images are loaded and displayed at once.
I would want the function to load one image at a time, so that image box is displayed, and then the next one, and next one, and so on. Is it possible with my function? What should I change? And also, is there a better way you could suggest to make that pattern that the boxes form? As you see now, it’s a lot of code counting each row of 4 boxes.
I greatly appreciate any help! this is the function below:
//Loading work objects from XML
var home:MovieClip = this;
xFirst = 0;
yFirst = 0;
yStep = 131;
xPlace = 0;
yPlace = 0;
var numOfItems:Number;
function loadXML(loaded) {
if (loaded) {
var nodes = this.firstChild.childNodes;
numOfItems = nodes.length;
var myArr = new Array();
for(var i=0;i<numOfItems;i++) {
if (i <= 4) {
xPlace = xFirst + (181*i);
yPlace = yFirst;
}
else if ((i >= 5) && (i <= 9)) {
xPlace = xFirst + ((181)*(i-5));
yPlace = yFirst + (yStep*1);
}
else if ((i >= 10) && (i <= 14)) {
xPlace = xFirst + ((181)*(i-10));
yPlace = yFirst + (yStep*2);
}
else if ((i >= 15) && (i <= 19)) {
xPlace = xFirst + ((181)*(i-15));
yPlace = yFirst + (yStep*3);
}
else if ((i >= 20) && (i <= 24)) {
xPlace = xFirst + ((181)*(i-20));
yPlace = yFirst + (yStep*4);
}
else if ((i >= 25) && (i <= 29)) {
xPlace = xFirst + ((181)*(i-25));
yPlace = yFirst + (yStep*5);
}
else if ((i >= 30) && (i <= 34)) {
xPlace = xFirst + ((181)*(i-30));
yPlace = yFirst + (yStep*6);
}
else if ((i >= 35) && (i <= 39)) {
xPlace = xFirst + ((181)*(i-35));
yPlace = yFirst + (yStep*7);
}
else if ((i >= 40) && (i <= 44)) {
xPlace = xFirst + ((181)*(i-40));
yPlace = yFirst + (yStep*8);
}
else if ((i >= 45) && (i <= 49)) {
xPlace = xFirst + ((181)*(i-45));
yPlace = yFirst + (yStep*9);
}
else if ((i >= 50) && (i <= 54)) {
xPlace = xFirst + ((181)*(i-50));
yPlace = yFirst + (yStep*10);
}
else if ((i >= 55) && (i <= 59)) {
xPlace = xFirst + ((181)*(i-55));
yPlace = yFirst + (yStep*11);
}
//trace(xPlace);
var t = work.attachMovie("work_object","work_object"+i,i+1, {_x: xPlace, _y: -130} );
t.wtext.type.text = nodes*.attributes.project;
t.wtext.year.text = nodes*.attributes.year;
t.showtype = nodes*.childNodes[4].attributes.type;
t.client = nodes*.attributes.client;
t.h1 = nodes*.childNodes[0].attributes.head;
t.t1 = nodes*.childNodes[0].firstChild.nodeValue;
t.h2 = nodes*.childNodes[1].attributes.head;
t.t2 = nodes*.childNodes[1].firstChild.nodeValue;
t.h3 = nodes*.childNodes[2].attributes.head;
t.t3 = nodes*.childNodes[2].firstChild.nodeValue;
t.workname = nodes*.childNodes[3].firstChild.nodeValue;
t.fullWidth = nodes*.attributes.width;
t.fullHeight = nodes*.attributes.height;
t.thumbLoad = nodes*.attributes.thumb;
t.tholder.loadMovie(t.thumbLoad);
//t.tholder.alphaTo(100, 1.5, "easeoutquart", 0.4);
t.tholder._alpha = 100;
t.slideTo(undefined, yPlace, 1.2, "easeoutquart", 0.8);
var imgNodes = nodes*.childNodes[4].childNodes;
numOfImgs = imgNodes.length;
t.imgArr = new Array();
for(var n=0;n<numOfImgs;n++) {
//t.image = imgNodes[n].attributes.src;
t.imgArr.push(imgNodes[n].attributes.src);
}
myArr* = t;
myArr*.onRollOver = rollover;
myArr*.onRollOut = rollout;
myArr*.onRelease = released;
_global.currentArr = myArr;
}
}
}
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = loadXML;
xml.load("xml/work.xml");