我正在向后加载我的MC,并且每页分隔10个。当它加载到舞台时,它无法相应地安排到网格。当我点击其他页面让它在上一个加载的XML对象之前运行另外10个时,它不会添加到数组中(我在重新加载XML之前清除了数组)
private function loadItem():void {
commentArray=new Array();
var columns:int=Math.ceil(stage.stageWidth/300);
var x_counter:Number=0;
var y_counter:Number=0;
var firstItem=myXMLList.length()-(currentPage*ItemPerPage);
var lastItem=firstItem-ItemPerPage;
if (lastItem<=0) {
lastItem=0;
}
//trace("firstItem="+firstItem, "lastItem="+lastItem)
for (i=(firstItem-1); i>lastItem; i--) {
cBox=new MovieClip();
//cbox created from here
items();
allcBox.addChild(cBox);
commentBox();
//moving object to top layers
cBox.setChildIndex(cBox.getChildByName("box"+i),0);
//arranging object in grids
for (l; l<ItemPerPage; l++) {
commentArray.push(cBox);
commentArray[l].x=(200+10)*x_counter;
commentArray[l].y=((60)*y_counter);
if (x_counter+1<columns) {
x_counter++;
} else {
x_counter=0;
y_counter++;
}
}
addChild(allcBox);
allcBox.y=-(allcBox.height+50);
}
}
//clearing off array to run a new set so could arrange item in grids
private function clearEverything():void {
commentArray.splice(0,commentArray.length);
currentPage=pagesArray.indexOf(event.target);
loadWishes();
}
我对这个问题的猜测可能是2循环,1使用++而另一个 - ?
答案 0 :(得分:0)
private function loadWishes():void {
commentArray=new Array();
var x_counter:Number=0;
var y_counter:Number=0;
var firstWishes=myXMLList.length()-(currentPage*wishesPerPage);
var lastWishes=firstWishes-wishesPerPage;
//start placing object
for (i=(firstWishes-1); i>lastWishes-1; i--) {
if (lastWishes<=0) {
lastWishes=1;
}
cBox=new MovieClip();
wishes();
//dropShadow.dShadow(sec);
//cBox.rotation=(Math.random()*5);
allcBox.addChild(cBox);
commentBox();
cBox.setChildIndex(cBox.getChildByName("box"+i),0);
commentArray.push(cBox);
addChild(allcBox);
}
for (var l:uint=0; l<commentArray.length; l++) {
commentArray[l].x=(200+10)*x_counter;
commentArray[l].y=((100)*y_counter);
if (x_counter+1<columns) {
x_counter++;
} else {
x_counter=0;
y_counter++;
}
}
allcBox.y=-(allcBox.height+50);
}