Groups | Blog | Home
all groups > flash actionscript > september 2006 >

flash actionscript : loading xml data and showing 5 xml nodes per page


icarusdown
9/30/2006 2:50:57 PM
I am loading data from xml file.
There is 12 XML nodes (in this case)
I don't want to show all xml data in Flash by default.
I am attaching one button on the stage for every 5 xml nodes (depends how much
data I want to show per one page, let's say 5)
So every time user clicks on one of this buttons, the data from startIndex to
endIndex of this button is shown

FIRST: I have a problem clearing the attached data every time user clicks the
button
SECOND: I have a problem with the last button's endIndex variable. it should
be 12 not 15 (in this case)!!!

Can someone help. I am attaching fla and xml

www.galahala.com/test.zip
coldMiner
9/30/2006 5:08:42 PM
This should fix first and second problem (replace your AS with this AS):


dataPerPage = 5;
//
var contentXML:XML = new XML();
var contentMC:Array = new Array();
contentXML.ignoreWhite = true;
//
contentXML.onLoad = function(Success) {
allData = this.firstChild.childNodes;
dataLength = allData.length;
if (Success) {
showData(0, dataPerPage);
}
};
contentXML.load("test.xml");
//
function showData(nStartIndex:Number, nEndIndex:Number) {
clearStage();
space = -1;
addButtons();
for (i=nStartIndex; i<nEndIndex; i++) {
if (allData[i].firstChild.firstChild.nodeValue) {
space++;
mcData = _root.attachMovie("data", "data"+i, i);
contentMC.push(mcData);
mcData._x = 100;
mcData._y = (mcData._height+5)*space;
//
dataContent = allData[i].firstChild.firstChild.nodeValue;
mcData.tData.text = dataContent;
}
}
}
//
function addButtons() {
for (var i = 0; i<dataLength/dataPerPage; i++) {
mcButton = _root.attachMovie("button", "button"+i, 1000+i);
mcButton._y = (mcButton._height+5)*i;
//
mcButton.startIndex = (i*dataPerPage);
// HERE IS THE PROBLEM //
mcButton.endIndex = ((i*dataPerPage)+dataPerPage);
if (mcButton.endIndex>dataLength) {
mcButton.endIndex = dataLength;
}
mcButton.tButton.text = mcButton.startIndex+1+"-"+mcButton.endIndex;
mcButton.onRelease = function() {
trace("startIndex = "+this.startIndex);
trace("endIndex = "+this.endIndex);
showData(this.startIndex, this.endIndex);
};
}
}
// HERE IS THE PROBLEM //
function clearStage(clearIndex) {
while (contentMC.length>0) {
contentMC[contentMC.length-1].removeMovieClip();
contentMC.pop();
}
}
icarusdown
9/30/2006 11:43:57 PM
AddThis Social Bookmark Button